diff options
author | Ben Gamari <bgamari.foss@gmail.com> | 2017-07-19 19:33:00 -0400 |
---|---|---|
committer | Ben Gamari <ben@smart-cactus.org> | 2017-07-19 22:05:03 -0400 |
commit | cc839c57ff9c80b50d39e8e2e66a18674bab3486 (patch) | |
tree | 2419246951641c0f37dfb981655e8c6e10385036 /compiler | |
parent | b066d936a919f6943de1acdc358d9e014b2cc663 (diff) | |
download | haskell-cc839c57ff9c80b50d39e8e2e66a18674bab3486.tar.gz |
Typeable: Ensure that promoted data family instance tycons get bindings
This fixes #13915, where the promoted tycons belonging to data family
instances wouldn't get Typeable bindings, resulting in missing
declarations.
Test Plan: Validate with included testcases
Reviewers: austin, simonpj
Reviewed By: simonpj
Subscribers: simonpj, RyanGlScott, rwbarton, thomie
GHC Trac Issues: #13915
Differential Revision: https://phabricator.haskell.org/D3759
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'' ] |