diff options
author | Ryan Scott <ryan.gl.scott@gmail.com> | 2023-01-24 19:58:10 -0500 |
---|---|---|
committer | Ryan Scott <ryan.gl.scott@gmail.com> | 2023-01-25 07:37:02 -0500 |
commit | 79133e932514141fdc1ace72da91272ab5aa8af3 (patch) | |
tree | 262c86757355a696d4e58d3bb8fbc4d3bdab8232 /compiler/GHC/Rename/Module.hs | |
parent | d151546e59a50158f25c3df6728b00d3c27bb4b9 (diff) | |
download | haskell-wip/T22817.tar.gz |
Handle `type data` properly in tyThingParent_maybewip/T22817
Unlike most other data constructors, data constructors declared with `type data`
are represented in `TyThing`s as `ATyCon` rather than `ADataCon`. The `ATyCon`
case in `tyThingParent_maybe` previously did not consider the possibility of
the underlying `TyCon` being a promoted data constructor, which led to the
oddities observed in #22817. This patch adds a dedicated special case in
`tyThingParent_maybe`'s `ATyCon` case for `type data` data constructors to fix
these oddities.
Fixes #22817.
Diffstat (limited to 'compiler/GHC/Rename/Module.hs')
-rw-r--r-- | compiler/GHC/Rename/Module.hs | 16 |
1 files changed, 11 insertions, 5 deletions
diff --git a/compiler/GHC/Rename/Module.hs b/compiler/GHC/Rename/Module.hs index fc6846e566..597d6acc27 100644 --- a/compiler/GHC/Rename/Module.hs +++ b/compiler/GHC/Rename/Module.hs @@ -2055,6 +2055,9 @@ Type data declarations have the syntax of `data` declarations (but not `newtype` declarations), either ordinary algebraic data types or GADTs, preceded by `type`, with the following restrictions: +(R0) 'data' decls only, not 'newtype' decls. This is checked by + the parser. + (R1) There are no data type contexts (even with the DatatypeContexts extension). @@ -2070,7 +2073,7 @@ preceded by `type`, with the following restrictions: The main parts of the implementation are: -* The parser recognizes `type data` (but not `type newtype`). +* (R0): The parser recognizes `type data` (but not `type newtype`). * During the initial construction of the AST, GHC.Parser.PostProcess.checkNewOrData sets the `Bool` argument of the @@ -2105,10 +2108,13 @@ The main parts of the implementation are: `dcPromotedField` is a `TyCon` (for `Zero`, say) that you can use in a type. -* After a `type data` declaration has been type-checked, the type-checker - environment entry for each constructor (`Zero` and `Succ` in our - example) is just the promoted type constructor, not the bundle required - for a data constructor. (GHC.Types.TyThing.implicitTyConThings) +* After a `type data` declaration has been type-checked, the + type-checker environment entry (a `TyThing`) for each constructor + (`Zero` and `Succ` in our example) is + - just an `ATyCon` for the promoted type constructor, + - not the bundle (`ADataCon` for the data con, `AnId` for the work id, + wrap id) required for a normal data constructor + See GHC.Types.TyThing.implicitTyConThings. * GHC.Core.TyCon.isDataKindsPromotedDataCon ignores promoted constructors from `type data`, which do not use the distinguishing quote mark added |