diff options
author | sheaf <sam.derbyshire@gmail.com> | 2023-04-03 20:20:58 +0200 |
---|---|---|
committer | Marge Bot <ben+marge-bot@smart-cactus.org> | 2023-04-04 01:04:50 -0400 |
commit | cd00e321d5d7aaee3999b283a2a2f0d77f7b3e8e (patch) | |
tree | a704f98f18cd1c902aadd6b424e67816a1df8e9f /compiler | |
parent | f7da530c80c0117d5684bb52481e4a40d7e724cc (diff) | |
download | haskell-cd00e321d5d7aaee3999b283a2a2f0d77f7b3e8e.tar.gz |
Relax assertion in varToRecFieldOcc
When using Template Haskell, it is possible to re-parent a field OccName
belonging to one data constructor to another data constructor. The
lsp-types package did this in order to "extend" a data constructor
with additional fields.
This ran into an assertion in 'varToRecFieldOcc'. This assertion
can simply be relaxed, as the resulting splices are perfectly sound.
Fixes #23220
Diffstat (limited to 'compiler')
-rw-r--r-- | compiler/GHC/Rename/Names.hs | 2 | ||||
-rw-r--r-- | compiler/GHC/Types/Name/Occurrence.hs | 9 |
2 files changed, 7 insertions, 4 deletions
diff --git a/compiler/GHC/Rename/Names.hs b/compiler/GHC/Rename/Names.hs index 570fb1485d..e46d803287 100644 --- a/compiler/GHC/Rename/Names.hs +++ b/compiler/GHC/Rename/Names.hs @@ -1011,7 +1011,7 @@ newRecordFieldLabel dup_fields_ok has_sel (dc:_) (L loc (FieldOcc _ (L _ fld))) , flSelector = selName } } where fld_occ = rdrNameOcc fld - dc_fs = (occNameFS $ nameOccName dc) + dc_fs = occNameFS $ nameOccName dc field -- Use an Exact RdrName as-is, to preserve the bindings -- of an already renamer-resolved field and its use diff --git a/compiler/GHC/Types/Name/Occurrence.hs b/compiler/GHC/Types/Name/Occurrence.hs index 8aecadf71e..964c313abd 100644 --- a/compiler/GHC/Types/Name/Occurrence.hs +++ b/compiler/GHC/Types/Name/Occurrence.hs @@ -465,9 +465,12 @@ varToRecFieldOcc dc (OccName ns s) = assert makes_sense $ mkRecFieldOccFS dc s where makes_sense = case ns of - VarName -> True - FldName con -> con == dc - _ -> False + VarName -> True + FldName {} -> True + -- NB: it's OK to change the parent data constructor, + -- see e.g. test T23220 in which we construct with TH + -- a datatype using the fields of a different datatype. + _ -> False recFieldToVarOcc :: HasDebugCallStack => OccName -> OccName recFieldToVarOcc (OccName _ns s) = mkVarOccFS s |