summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlfredo Di Napoli <alfredo@well-typed.com>2021-07-06 10:32:25 +0200
committerMarge Bot <ben+marge-bot@smart-cactus.org>2021-07-09 08:46:44 -0400
commitbc2c00dd7c4313d3aa10d1d1a8258e1bb360ad2d (patch)
tree64952912352a6e05f26761052d96d9772c9a6282
parent1e8055175cbb63e06540610a0452906981584e6b (diff)
downloadhaskell-bc2c00dd7c4313d3aa10d1d1a8258e1bb360ad2d.tar.gz
Add TcRnIllegalPatSynDecl to TcRnMessage
-rw-r--r--compiler/GHC/Rename/Bind.hs5
-rw-r--r--compiler/GHC/Tc/Errors/Ppr.hs8
-rw-r--r--compiler/GHC/Tc/Errors/Types.hs14
3 files changed, 23 insertions, 4 deletions
diff --git a/compiler/GHC/Rename/Bind.hs b/compiler/GHC/Rename/Bind.hs
index 79b0a5661a..dd52c85351 100644
--- a/compiler/GHC/Rename/Bind.hs
+++ b/compiler/GHC/Rename/Bind.hs
@@ -455,10 +455,7 @@ rnBindLHS name_maker _ (PatSynBind x psb@PSB{ psb_id = rdrname })
; return (PatSynBind x psb{ psb_ext = noAnn, psb_id = name }) }
where
localPatternSynonymErr :: TcRnMessage
- localPatternSynonymErr
- = TcRnUnknownMessage $ mkPlainError noHints $
- hang (text "Illegal pattern synonym declaration for" <+> quotes (ppr rdrname))
- 2 (text "Pattern synonym declarations are only valid at top level")
+ localPatternSynonymErr = TcRnIllegalPatSynDecl rdrname
rnBindLHS _ _ b = pprPanic "rnBindHS" (ppr b)
diff --git a/compiler/GHC/Tc/Errors/Ppr.hs b/compiler/GHC/Tc/Errors/Ppr.hs
index fc69df5379..a1773a12ed 100644
--- a/compiler/GHC/Tc/Errors/Ppr.hs
+++ b/compiler/GHC/Tc/Errors/Ppr.hs
@@ -67,6 +67,10 @@ instance Diagnostic TcRnMessage where
hang (text "solveWanteds: too many iterations"
<+> parens (text "limit =" <+> ppr limit))
2 (text "Unsolved:" <+> ppr wc)
+ TcRnIllegalPatSynDecl rdrname
+ -> mkSimpleDecorated $
+ hang (text "Illegal pattern synonym declaration for" <+> quotes (ppr rdrname))
+ 2 (text "Pattern synonym declarations are only valid at top level")
diagnosticReason = \case
TcRnUnknownMessage m
@@ -96,6 +100,8 @@ instance Diagnostic TcRnMessage where
-> ErrorWithoutFlag
TcRnSimplifierTooManyIterations{}
-> ErrorWithoutFlag
+ TcRnIllegalPatSynDecl{}
+ -> ErrorWithoutFlag
diagnosticHints = \case
TcRnUnknownMessage m
@@ -125,6 +131,8 @@ instance Diagnostic TcRnMessage where
-> noHints
TcRnSimplifierTooManyIterations{}
-> [SuggestIncreaseSimplifierIterations]
+ TcRnIllegalPatSynDecl{}
+ -> noHints
messageWithInfoDiagnosticMessage :: UnitState
-> ErrInfo
diff --git a/compiler/GHC/Tc/Errors/Types.hs b/compiler/GHC/Tc/Errors/Types.hs
index 1e8a18a8a0..3a5d724c75 100644
--- a/compiler/GHC/Tc/Errors/Types.hs
+++ b/compiler/GHC/Tc/Errors/Types.hs
@@ -212,6 +212,20 @@ data TcRnMessage where
-> WantedConstraints
-> TcRnMessage
+ {-| TcRnIllegalPatSynDecl is an error that occurs whenever
+ there is an illegal pattern synonym declaration.
+
+ Examples(s):
+
+ varWithLocalPatSyn x = case x of
+ P -> ()
+ where
+ pattern P = () -- not valid, it can't be local, it must be defined at top-level.
+
+ Test cases: patsyn/should_fail/local
+ -}
+ TcRnIllegalPatSynDecl :: !(LIdP GhcPs) -> TcRnMessage
+
-- | Where a shadowed name comes from
data ShadowedNameProvenance