diff options
author | uhbif19 <uhbif19@gmail.com> | 2022-05-15 11:53:27 +0300 |
---|---|---|
committer | uhbif19 <uhbif19@gmail.com> | 2022-06-09 20:22:47 +0300 |
commit | 7eab75bb2d176ea09de535be17130dc9dae42a02 (patch) | |
tree | c4b8276bc2ba19cfe783061f0fb8c92c637f591e /compiler/GHC/Tc | |
parent | 8727be73296c16c11e01f42691ea27738436b28b (diff) | |
download | haskell-7eab75bb2d176ea09de535be17130dc9dae42a02.tar.gz |
Remove TcRnUnknownMessage usage from GHC.Rename.Env #20115
Diffstat (limited to 'compiler/GHC/Tc')
-rw-r--r-- | compiler/GHC/Tc/Errors/Ppr.hs | 32 | ||||
-rw-r--r-- | compiler/GHC/Tc/Errors/Types.hs | 70 |
2 files changed, 102 insertions, 0 deletions
diff --git a/compiler/GHC/Tc/Errors/Ppr.hs b/compiler/GHC/Tc/Errors/Ppr.hs index 3dc1ea685b..3ab4fc2927 100644 --- a/compiler/GHC/Tc/Errors/Ppr.hs +++ b/compiler/GHC/Tc/Errors/Ppr.hs @@ -69,6 +69,7 @@ import GHC.Types.Var.Env import GHC.Unit.State (pprWithUnitState, UnitState) import GHC.Unit.Module +import GHC.Unit.Module.Warnings ( pprWarningTxtForMsg ) import GHC.Data.Bag import GHC.Data.FastString @@ -668,6 +669,9 @@ instance Diagnostic TcRnMessage where -> mkSimpleDecorated $ text "Illegal operator" <+> quotes (ppr op) <+> text "in type" <+> quotes (ppr overall_ty) + TcRnIllegalTypeOperatorDecl name + -> mkSimpleDecorated $ + text "Illegal declaration of a type or class operator" <+> quotes (ppr name) TcRnGADTMonoLocalBinds -> mkSimpleDecorated $ fsep [ text "Pattern matching on GADTs without MonoLocalBinds" @@ -894,6 +898,7 @@ instance Diagnostic TcRnMessage where RecDataConPE -> same_rec_group_msg ClassPE -> same_rec_group_msg TyConPE -> same_rec_group_msg + TermVariablePE -> text "term variables cannot be promoted" same_rec_group_msg = text "it is defined and used in the same recursive group" TcRnMatchesHaveDiffNumArgs argsContext match1 bad_matches -> mkSimpleDecorated $ @@ -937,6 +942,20 @@ instance Diagnostic TcRnMessage where -> mkSimpleDecorated $ text "You cannot SPECIALISE" <+> quotes (ppr name) <+> text "because its definition is not visible in this module" + TcRnNameByTemplateHaskellQuote name -> mkSimpleDecorated $ + text "Cannot redefine a Name retrieved by a Template Haskell quote:" <+> ppr name + TcRnIllegalBindingOfBuiltIn name -> mkSimpleDecorated $ + text "Illegal binding of built-in syntax:" <+> ppr name + TcRnDeprecated {depr_occ, depr_msg, depr_import_mod, depr_defined_mod} -> mkSimpleDecorated $ + sep [ sep [ text "In the use of" + <+> pprNonVarNameSpace (occNameSpace depr_occ) + <+> quotes (ppr depr_occ) + , parens impMsg <> colon ] + , pprWarningTxtForMsg depr_msg ] + where + impMsg = text "imported from" <+> ppr depr_import_mod <> extra + extra | depr_import_mod == depr_defined_mod = empty + | otherwise = text ", but defined in" <+> ppr depr_defined_mod diagnosticReason = \case TcRnUnknownMessage m @@ -1167,6 +1186,8 @@ instance Diagnostic TcRnMessage where -> WarningWithFlag Opt_WarnTypeEqualityRequiresOperators TcRnIllegalTypeOperator {} -> ErrorWithoutFlag + TcRnIllegalTypeOperatorDecl {} + -> ErrorWithoutFlag TcRnGADTMonoLocalBinds {} -> WarningWithFlag Opt_WarnGADTMonoLocalBinds TcRnIncorrectNameSpace {} @@ -1243,6 +1264,12 @@ instance Diagnostic TcRnMessage where -> WarningWithoutFlag TcRnSpecialiseNotVisible{} -> WarningWithoutFlag + TcRnNameByTemplateHaskellQuote{} + -> ErrorWithoutFlag + TcRnIllegalBindingOfBuiltIn{} + -> ErrorWithoutFlag + TcRnDeprecated{} + -> WarningWithFlag Opt_WarnWarningsDeprecations diagnosticHints = \case TcRnUnknownMessage m @@ -1467,6 +1494,8 @@ instance Diagnostic TcRnMessage where -> [suggestExtension LangExt.TypeOperators] TcRnIllegalTypeOperator {} -> [suggestExtension LangExt.TypeOperators] + TcRnIllegalTypeOperatorDecl {} + -> [suggestExtension LangExt.TypeOperators] TcRnGADTMonoLocalBinds {} -> [suggestAnyExtension [LangExt.GADTs, LangExt.TypeFamilies]] TcRnIncorrectNameSpace nm is_th_use @@ -1551,6 +1580,9 @@ instance Diagnostic TcRnMessage where -> noHints TcRnSpecialiseNotVisible name -> [SuggestSpecialiseVisibilityHints name] + TcRnNameByTemplateHaskellQuote{} -> noHints + TcRnIllegalBindingOfBuiltIn{} -> noHints + TcRnDeprecated{} -> noHints -- | Change [x] to "x", [x, y] to "x and y", [x, y, z] to "x, y, and z", diff --git a/compiler/GHC/Tc/Errors/Types.hs b/compiler/GHC/Tc/Errors/Types.hs index ad5f3db81b..fff6ff7dc9 100644 --- a/compiler/GHC/Tc/Errors/Types.hs +++ b/compiler/GHC/Tc/Errors/Types.hs @@ -113,6 +113,7 @@ import GHC.Data.FastString (FastString) import qualified Data.List.NonEmpty as NE import Data.Typeable hiding (TyCon) import qualified Data.Semigroup as Semigroup +import GHC.Unit.Module.Warnings (WarningTxt) {- Note [Migrating TcM Messages] @@ -1621,6 +1622,27 @@ data TcRnMessage where -} TcRnIllegalTypeOperator :: !SDoc -> !RdrName -> TcRnMessage + {-| TcRnIllegalTypeOperatorDecl is an error that occurs when a type or class + operator is declared without the TypeOperators extension. + + See Note [Type and class operator definitions] + + Example: + {-# LANGUAGE Haskell2010 #-} + {-# LANGUAGE MultiParamTypeClasses #-} + + module T3265 where + + data a :+: b = Left a | Right b + + class a :*: b where {} + + + Test cases: T3265, tcfail173 + -} + TcRnIllegalTypeOperatorDecl :: !RdrName -> TcRnMessage + + {-| TcRnGADTMonoLocalBinds is a warning controlled by -Wgadt-mono-local-binds that occurs when pattern matching on a GADT when -XMonoLocalBinds is off. @@ -2006,6 +2028,7 @@ data TcRnMessage where polykinds/T15116a saks/should_fail/T16727a saks/should_fail/T16727b + rename/should_fail/T12686 -} TcRnUnpromotableThing :: !Name -> !PromotionErr -> TcRnMessage @@ -2109,6 +2132,50 @@ data TcRnMessage where -} TcRnSpecialiseNotVisible :: !Name -> TcRnMessage + {- TcRnNameByTemplateHaskellQuote is an error that occurs when one tries + to use a Template Haskell splice to define a top-level identifier with + an already existing name. + + (See issue #13968 (closed) on GHC's issue tracker for more details) + + Example(s): + + $(pure [ValD (VarP 'succ) (NormalB (ConE 'True)) []]) + + Test cases: + T13968 + -} + TcRnNameByTemplateHaskellQuote :: !RdrName -> TcRnMessage + + {- TcRnIllegalBindingOfBuiltIn is an error that occurs when one uses built-in + syntax for data constructors or class names. + + Use an OccName here because we don't want to print Prelude.(,) + + Test cases: + rename/should_fail/T14907b + rename/should_fail/rnfail042 + -} + TcRnIllegalBindingOfBuiltIn :: !OccName -> TcRnMessage + + {- TcRnDeprecated is a warning that can happen when usage of something + is deprecated. + + Test cases: + DeprU + T5281 + T5867 + rn050 + rn066 + T3303 + -} + TcRnDeprecated :: { + depr_occ :: OccName, + depr_msg :: WarningTxt GhcRn, + depr_import_mod :: ModuleName, + depr_defined_mod :: ModuleName + } -> TcRnMessage + -- | Specifies which back ends can handle a requested foreign import or export type ExpectedBackends = [Backend] @@ -3081,6 +3148,7 @@ data PromotionErr | RecDataConPE -- Data constructor in a recursive loop -- See Note [Recursion and promoting data constructors] in GHC.Tc.TyCl + | TermVariablePE -- See Note [Promoted variables in types] | NoDataKindsDC -- -XDataKinds not enabled (for a datacon) instance Outputable PromotionErr where @@ -3092,6 +3160,7 @@ instance Outputable PromotionErr where <+> parens (ppr pred) ppr RecDataConPE = text "RecDataConPE" ppr NoDataKindsDC = text "NoDataKindsDC" + ppr TermVariablePE = text "TermVariablePE" pprPECategory :: PromotionErr -> SDoc pprPECategory = text . capitalise . peCategory @@ -3104,6 +3173,7 @@ peCategory FamDataConPE = "data constructor" peCategory ConstrainedDataConPE{} = "data constructor" peCategory RecDataConPE = "data constructor" peCategory NoDataKindsDC = "data constructor" +peCategory TermVariablePE = "term variable" -- | Stores the information to be reported in a representation-polymorphism -- error message. |