Skip to content

Commit 79b98f0

Browse files
committed
Introduces compatibility function dataConInstOrigArgTys', which calls dataConInstArgTys and selecting only non-class types
1 parent 6c0767b commit 79b98f0

File tree

1 file changed

+12
-2
lines changed

1 file changed

+12
-2
lines changed

plugins/tactics/src/Ide/Plugin/Tactic/CodeGen.hs

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -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 = dataConInstOrigArgTys 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+
5767
destruct' :: (DataCon -> Judgement -> Rule) -> OccName -> Judgement -> Rule
5868
destruct' 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)
8797
buildDataCon jdg dc apps = do
88-
let args = dataConInstOrigArgTys dc apps
98+
let args = dataConInstOrigArgTys' dc apps
8999
sgs <- traverse (newSubgoal . flip withNewGoal jdg . CType) args
90100
pure
91101
. noLoc

0 commit comments

Comments
 (0)