diff options
author | Simon Peyton Jones <simonpj@microsoft.com> | 2021-07-27 18:07:11 +0100 |
---|---|---|
committer | Marge Bot <ben+marge-bot@smart-cactus.org> | 2022-02-04 20:36:20 -0500 |
commit | 6af8e71ed7e749ba94e7a7eaf8b2229341bf35da (patch) | |
tree | aabf6c233d2067ca9f62b5c5ff4ec83576e58bd9 /compiler/GHC/Rename/Utils.hs | |
parent | bf495f7206741c81135c04ce6bb943c4a6729e80 (diff) | |
download | haskell-6af8e71ed7e749ba94e7a7eaf8b2229341bf35da.tar.gz |
Improve errors for non-existent labels
This patch fixes #17469, by improving matters when you use
non-existent field names in a record construction:
data T = MkT { x :: Int }
f v = MkT { y = 3 }
The check is now made in the renamer, in GHC.Rename.Env.lookupRecFieldOcc.
That in turn led to a spurious error in T9975a, which is fixed by
making GHC.Rename.Names.extendGlobalRdrEnvRn fail fast if it finds
duplicate bindings. See Note [Fail fast on duplicate definitions]
in that module for more details.
This patch was originated and worked on by Alex D (@nineonine)
Diffstat (limited to 'compiler/GHC/Rename/Utils.hs')
-rw-r--r-- | compiler/GHC/Rename/Utils.hs | 8 |
1 files changed, 7 insertions, 1 deletions
diff --git a/compiler/GHC/Rename/Utils.hs b/compiler/GHC/Rename/Utils.hs index 6497a51c02..1647c19e32 100644 --- a/compiler/GHC/Rename/Utils.hs +++ b/compiler/GHC/Rename/Utils.hs @@ -18,7 +18,7 @@ module GHC.Rename.Utils ( warnForallIdentifier, checkUnusedRecordWildcard, mkFieldEnv, - badQualBndrErr, typeAppErr, + badQualBndrErr, typeAppErr, badFieldConErr, wrapGenSpan, genHsVar, genLHsVar, genHsApp, genHsApps, genAppType, genHsIntegralLit, genHsTyLit, HsDocContext(..), pprHsDocContext, @@ -616,6 +616,12 @@ typeAppErr what (L _ k) <+> quotes (char '@' <> ppr k)) 2 (text "Perhaps you intended to use TypeApplications") +badFieldConErr :: Name -> FieldLabelString -> TcRnMessage +badFieldConErr con field + = TcRnUnknownMessage $ mkPlainError noHints $ + hsep [text "Constructor" <+> quotes (ppr con), + text "does not have field", quotes (ppr field)] + -- | Ensure that a boxed or unboxed tuple has arity no larger than -- 'mAX_TUPLE_SIZE'. checkTupSize :: Int -> TcM () |