@@ -23,6 +23,7 @@ import GHC.SourceGen.Binds
23
23
import GHC.SourceGen.Expr
24
24
import GHC.SourceGen.Overloaded
25
25
import GHC.SourceGen.Pat
26
+ import Ide.Plugin.Tactic.GHC
26
27
import Ide.Plugin.Tactic.Judgements
27
28
import Ide.Plugin.Tactic.Machinery
28
29
import Ide.Plugin.Tactic.Naming
@@ -120,13 +121,30 @@ unzipTrace l =
120
121
121
122
122
123
-- | Essentially same as 'dataConInstOrigArgTys' in GHC,
123
- -- but we need some tweaks in GHC >= 8.8.
124
- -- Since old 'dataConInstArgTys' seems working with >= 8.8,
125
- -- we just filter out non-class types in the result.
126
- dataConInstOrigArgTys' :: DataCon -> [Type ] -> [Type ]
127
- dataConInstOrigArgTys' con ty =
128
- let tys0 = dataConInstArgTys con ty
129
- in filter (maybe True (not . isClassTyCon) . tyConAppTyCon_maybe) tys0
124
+ -- but only accepts universally quantified types as the second arguments
125
+ -- and automatically introduces existentials.
126
+ --
127
+ -- NOTE: The behaviour depends on GHC's 'dataConInstOrigArgTys'.
128
+ -- We need some tweaks if the compiler changes the implementation.
129
+ dataConInstOrigArgTys'
130
+ :: DataCon
131
+ -- ^ 'DataCon'structor
132
+ -> [Type ]
133
+ -- ^ /Universally/ quantified type arguments to a result type.
134
+ -- It /MUST NOT/ contain any dictionaries, coercion and existentials.
135
+ --
136
+ -- For example, for @MkMyGADT :: b -> MyGADT a c@, we
137
+ -- must pass @[a, c]@ as this argument but not @b@, as @b@ is an existential.
138
+ -> [Type ]
139
+ -- ^ Types of arguments to the DataCon with returned type is instantiated with the second argument.
140
+ dataConInstOrigArgTys' con uniTys =
141
+ let exvars = dataConExTys con
142
+ in dataConInstOrigArgTys con $
143
+ uniTys ++ fmap mkTyVarTy exvars
144
+ -- Rationale: At least in GHC <= 8.10, 'dataConInstOrigArgTys'
145
+ -- unifies the second argument with DataCon's universals followed by existentials.
146
+ -- If the definition of 'dataConInstOrigArgTys' changes,
147
+ -- this place must be changed accordingly.
130
148
131
149
------------------------------------------------------------------------------
132
150
-- | Combinator for performing case splitting, and running sub-rules on the
0 commit comments