@@ -38,7 +38,7 @@ destructMatches f f2 t jdg = do
3838 case dcs of
3939 [] -> throwError $ GoalMismatch " destruct" g
4040 _ -> for dcs $ \ dc -> do
41- let args = dataConInstArgTys dc apps
41+ let args = dataConInstOrigArgTys' dc apps
4242 names <- mkManyGoodNames hy args
4343
4444 let pat :: Pat GhcPs
@@ -51,9 +51,19 @@ destructMatches f f2 t jdg = do
5151 pure $ match [pat] $ unLoc sg
5252
5353
54+ -- | Essentially same as 'dataConInstOrigArgTys' in GHC,
55+ -- but we need some tweaks in GHC >= 8.8.
56+ -- Since old 'dataConInstArgTys' seems working with >= 8.8,
57+ -- we just filter out non-class types in the result.
58+ dataConInstOrigArgTys' :: DataCon -> [Type ] -> [Type ]
59+ dataConInstOrigArgTys' con ty =
60+ let tys0 = dataConInstArgTys con ty
61+ in filter (maybe True (not . isClassTyCon) . tyConAppTyCon_maybe) tys0
62+
5463------------------------------------------------------------------------------
5564-- | Combinator for performing case splitting, and running sub-rules on the
5665-- resulting matches.
66+
5767destruct' :: (DataCon -> Judgement -> Rule ) -> OccName -> Judgement -> Rule
5868destruct' f term jdg = do
5969 let hy = jHypothesis jdg
@@ -85,7 +95,7 @@ buildDataCon
8595 -> [Type ] -- ^ Type arguments for the data con
8696 -> RuleM (LHsExpr GhcPs )
8797buildDataCon jdg dc apps = do
88- let args = dataConInstArgTys dc apps
98+ let args = dataConInstOrigArgTys' dc apps
8999 sgs <- traverse (newSubgoal . flip withNewGoal jdg . CType ) args
90100 pure
91101 . noLoc
0 commit comments