diff options
Diffstat (limited to 'compiler')
-rw-r--r-- | compiler/typecheck/TcEnv.hs | 11 | ||||
-rw-r--r-- | compiler/typecheck/TcRnTypes.hs | 3 | ||||
-rw-r--r-- | compiler/typecheck/TcTypeable.hs | 8 |
3 files changed, 13 insertions, 9 deletions
diff --git a/compiler/typecheck/TcEnv.hs b/compiler/typecheck/TcEnv.hs index 935ad3dcb7..12f8a1df4f 100644 --- a/compiler/typecheck/TcEnv.hs +++ b/compiler/typecheck/TcEnv.hs @@ -625,15 +625,18 @@ Consider data S = MkS (Proxy 'MkT) Is it ok to use the promoted data family instance constructor 'MkT' in -the data declaration for S? No, we don't allow this. It *might* make -sense, but at least it would mean that we'd have to interleave -typechecking instances and data types, whereas at present we do data -types *then* instances. +the data declaration for S (where both declarations live in the same module)? +No, we don't allow this. It *might* make sense, but at least it would mean that +we'd have to interleave typechecking instances and data types, whereas at +present we do data types *then* instances. So to check for this we put in the TcLclEnv a binding for all the family constructors, bound to AFamDataCon, so that if we trip over 'MkT' when type checking 'S' we'll produce a decent error message. +Trac #12088 describes this limitation. Of course, when MkT and S live in +different modules then all is well. + Note [Don't promote pattern synonyms] ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ We never promote pattern synonyms. diff --git a/compiler/typecheck/TcRnTypes.hs b/compiler/typecheck/TcRnTypes.hs index 3992a7e662..6383b57c28 100644 --- a/compiler/typecheck/TcRnTypes.hs +++ b/compiler/typecheck/TcRnTypes.hs @@ -1077,7 +1077,8 @@ data PromotionErr | ClassPE -- Ditto Class | FamDataConPE -- Data constructor for a data family - -- See Note [AFamDataCon: not promoting data family constructors] in TcRnDriver + -- See Note [AFamDataCon: not promoting data family constructors] + -- in TcEnv. | PatSynPE -- Pattern synonyms -- See Note [Don't promote pattern synonyms] in TcEnv diff --git a/compiler/typecheck/TcTypeable.hs b/compiler/typecheck/TcTypeable.hs index e7a427f6e1..2fcca7ffc2 100644 --- a/compiler/typecheck/TcTypeable.hs +++ b/compiler/typecheck/TcTypeable.hs @@ -170,7 +170,7 @@ mkTypeableBinds | tc `elem` [runtimeRepTyCon, vecCountTyCon, vecElemTyCon] = False | otherwise = - (not (isFamInstTyCon tc) && isAlgTyCon tc) + isAlgTyCon tc || isDataFamilyTyCon tc || isClassTyCon tc @@ -243,12 +243,12 @@ todoForTyCons mod mod_id tycons = do } | tc <- tycons , tc' <- tc : tyConATs tc - -- If the tycon itself isn't typeable then we needn't look - -- at its promoted datacons as their kinds aren't Typeable - , Just _ <- pure $ tyConRepName_maybe tc' -- We need type representations for any associated types , let promoted = map promoteDataCon (tyConDataCons tc') , tc'' <- tc' : promoted + -- Don't make bindings for data-family instance tycons. + -- Do, however, make them for their promoted datacon (see #13915). + , not $ isFamInstTyCon tc'' , Just rep_name <- pure $ tyConRepName_maybe tc'' , typeIsTypeable $ dropForAlls $ tyConKind tc'' ] |