summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlfredo Di Napoli <alfredo@well-typed.com>2021-07-06 10:41:00 +0200
committerMarge Bot <ben+marge-bot@smart-cactus.org>2021-07-09 08:46:44 -0400
commit52353476eeac58870bb9053af58ca35b473141a7 (patch)
tree7a97d8f80ea3ed1a6b0d29cb38d2a332007a0ac5
parentbc2c00dd7c4313d3aa10d1d1a8258e1bb360ad2d (diff)
downloadhaskell-52353476eeac58870bb9053af58ca35b473141a7.tar.gz
Add TcRnEmptyRecordUpdate to TcRnMessage
-rw-r--r--compiler/GHC/Rename/Pat.hs5
-rw-r--r--compiler/GHC/Tc/Errors/Ppr.hs6
-rw-r--r--compiler/GHC/Tc/Errors/Types.hs11
3 files changed, 18 insertions, 4 deletions
diff --git a/compiler/GHC/Rename/Pat.hs b/compiler/GHC/Rename/Pat.hs
index 606c9a372b..4fc6093f3e 100644
--- a/compiler/GHC/Rename/Pat.hs
+++ b/compiler/GHC/Rename/Pat.hs
@@ -873,7 +873,7 @@ rnHsRecUpdFields flds
-- Check for an empty record update e {}
-- NB: don't complain about e { .. }, because rn_dotdot has done that already
- ; when (null flds) $ addErr emptyUpdateErr
+ ; when (null flds) $ addErr TcRnEmptyRecordUpdate
; return (flds1, plusFVs fvss) }
where
@@ -935,9 +935,6 @@ badDotDotCon con
vcat [ text "Illegal `..' notation for constructor" <+> quotes (ppr con)
, nest 2 (text "The constructor has no labelled fields") ]
-emptyUpdateErr :: TcRnMessage
-emptyUpdateErr = TcRnUnknownMessage $ mkPlainError noHints $ text "Empty record update"
-
badPun :: Located RdrName -> TcRnMessage
badPun fld = TcRnUnknownMessage $ mkPlainError noHints $
vcat [text "Illegal use of punning for field" <+> quotes (ppr fld),
diff --git a/compiler/GHC/Tc/Errors/Ppr.hs b/compiler/GHC/Tc/Errors/Ppr.hs
index a1773a12ed..29d36eda3c 100644
--- a/compiler/GHC/Tc/Errors/Ppr.hs
+++ b/compiler/GHC/Tc/Errors/Ppr.hs
@@ -71,6 +71,8 @@ instance Diagnostic TcRnMessage where
-> mkSimpleDecorated $
hang (text "Illegal pattern synonym declaration for" <+> quotes (ppr rdrname))
2 (text "Pattern synonym declarations are only valid at top level")
+ TcRnEmptyRecordUpdate
+ -> mkSimpleDecorated $ text "Empty record update"
diagnosticReason = \case
TcRnUnknownMessage m
@@ -102,6 +104,8 @@ instance Diagnostic TcRnMessage where
-> ErrorWithoutFlag
TcRnIllegalPatSynDecl{}
-> ErrorWithoutFlag
+ TcRnEmptyRecordUpdate
+ -> ErrorWithoutFlag
diagnosticHints = \case
TcRnUnknownMessage m
@@ -133,6 +137,8 @@ instance Diagnostic TcRnMessage where
-> [SuggestIncreaseSimplifierIterations]
TcRnIllegalPatSynDecl{}
-> noHints
+ TcRnEmptyRecordUpdate{}
+ -> noHints
messageWithInfoDiagnosticMessage :: UnitState
-> ErrInfo
diff --git a/compiler/GHC/Tc/Errors/Types.hs b/compiler/GHC/Tc/Errors/Types.hs
index 3a5d724c75..6e96256db2 100644
--- a/compiler/GHC/Tc/Errors/Types.hs
+++ b/compiler/GHC/Tc/Errors/Types.hs
@@ -226,6 +226,17 @@ data TcRnMessage where
-}
TcRnIllegalPatSynDecl :: !(LIdP GhcPs) -> TcRnMessage
+ {-| TcRnEmptyRecordUpdate is an error that occurs whenever
+ a record is updated without specifying any field.
+
+ Examples(s):
+
+ $(deriveJSON defaultOptions{} ''Bad) -- not ok, no fields selected for update of defaultOptions
+
+ Test cases: th/T12788
+ -}
+ TcRnEmptyRecordUpdate :: TcRnMessage
+
-- | Where a shadowed name comes from
data ShadowedNameProvenance