diff options
author | Giles Anderson <agander@gmail.com> | 2022-08-29 23:01:47 +0200 |
---|---|---|
committer | Marge Bot <ben+marge-bot@smart-cactus.org> | 2022-11-09 09:27:52 -0500 |
commit | 92ccb8de9624ea930d66152b2f6a181941a497c9 (patch) | |
tree | 6231d4f2c6a7e4e60a18f7d9f128ffab1e0ffe10 /compiler/GHC/Tc/Errors | |
parent | 080fffa1015bcc0cff8ab4ad1eeb507fb7a13383 (diff) | |
download | haskell-92ccb8de9624ea930d66152b2f6a181941a497c9.tar.gz |
Use TcRnDiagnostic in GHC.Tc.TyCl.Instance (#20117)
The following `TcRnDiagnostic` messages have been introduced:
TcRnWarnUnsatisfiedMinimalDefinition
TcRnMisplacedInstSig
TcRnBadBootFamInstDeclErr
TcRnIllegalFamilyInstance
TcRnAssocInClassErr
TcRnBadFamInstDecl
TcRnNotOpenFamily
Diffstat (limited to 'compiler/GHC/Tc/Errors')
-rw-r--r-- | compiler/GHC/Tc/Errors/Ppr.hs | 56 | ||||
-rw-r--r-- | compiler/GHC/Tc/Errors/Types.hs | 87 |
2 files changed, 143 insertions, 0 deletions
diff --git a/compiler/GHC/Tc/Errors/Ppr.hs b/compiler/GHC/Tc/Errors/Ppr.hs index 60b92643da..ad23585fd0 100644 --- a/compiler/GHC/Tc/Errors/Ppr.hs +++ b/compiler/GHC/Tc/Errors/Ppr.hs @@ -1154,6 +1154,34 @@ instance Diagnostic TcRnMessage where False -> text (TH.pprint item)) TcRnReportCustomQuasiError _ msg -> mkSimpleDecorated $ text msg TcRnInterfaceLookupError _ sdoc -> mkSimpleDecorated sdoc + TcRnUnsatisfiedMinimalDef mindef + -> mkSimpleDecorated $ + vcat [text "No explicit implementation for" + ,nest 2 $ pprBooleanFormulaNice mindef + ] + TcRnMisplacedInstSig name hs_ty + -> mkSimpleDecorated $ + vcat [ hang (text "Illegal type signature in instance declaration:") + 2 (hang (pprPrefixName name) + 2 (dcolon <+> ppr hs_ty)) + ] + TcRnBadBootFamInstDecl {} + -> mkSimpleDecorated $ + text "Illegal family instance in hs-boot file" + TcRnIllegalFamilyInstance tycon + -> mkSimpleDecorated $ + vcat [ text "Illegal family instance for" <+> quotes (ppr tycon) + , nest 2 $ parens (ppr tycon <+> text "is not an indexed type family")] + TcRnMissingClassAssoc name + -> mkSimpleDecorated $ + text "Associated type" <+> quotes (ppr name) <+> + text "must be inside a class instance" + TcRnBadFamInstDecl tc_name + -> mkSimpleDecorated $ + text "Illegal family instance for" <+> quotes (ppr tc_name) + TcRnNotOpenFamily tc + -> mkSimpleDecorated $ + text "Illegal instance for closed family" <+> quotes (ppr tc) diagnosticReason = \case TcRnUnknownMessage m @@ -1522,6 +1550,20 @@ instance Diagnostic TcRnMessage where -> if isError then ErrorWithoutFlag else WarningWithoutFlag TcRnInterfaceLookupError{} -> ErrorWithoutFlag + TcRnUnsatisfiedMinimalDef{} + -> WarningWithFlag (Opt_WarnMissingMethods) + TcRnMisplacedInstSig{} + -> ErrorWithoutFlag + TcRnBadBootFamInstDecl{} + -> ErrorWithoutFlag + TcRnIllegalFamilyInstance{} + -> ErrorWithoutFlag + TcRnMissingClassAssoc{} + -> ErrorWithoutFlag + TcRnBadFamInstDecl{} + -> ErrorWithoutFlag + TcRnNotOpenFamily{} + -> ErrorWithoutFlag diagnosticHints = \case TcRnUnknownMessage m @@ -1892,6 +1934,20 @@ instance Diagnostic TcRnMessage where -> noHints TcRnInterfaceLookupError{} -> noHints + TcRnUnsatisfiedMinimalDef{} + -> noHints + TcRnMisplacedInstSig{} + -> [suggestExtension LangExt.InstanceSigs] + TcRnBadBootFamInstDecl{} + -> noHints + TcRnIllegalFamilyInstance{} + -> noHints + TcRnMissingClassAssoc{} + -> noHints + TcRnBadFamInstDecl{} + -> [suggestExtension LangExt.TypeFamilies] + TcRnNotOpenFamily{} + -> noHints diagnosticCode = constructorCode diff --git a/compiler/GHC/Tc/Errors/Types.hs b/compiler/GHC/Tc/Errors/Types.hs index 053e53a16a..2baccd1ee1 100644 --- a/compiler/GHC/Tc/Errors/Types.hs +++ b/compiler/GHC/Tc/Errors/Types.hs @@ -2545,6 +2545,93 @@ data TcRnMessage where -} TcRnInterfaceLookupError :: !Name -> !SDoc -> TcRnMessage + {- | TcRnUnsatisfiedMinimalDef is a warning that occurs when a class instance + is missing methods that are required by the minimal definition. + + Example: + class C a where + foo :: a -> a + instance C () -- | foo needs to be defined here + + Test cases: + testsuite/tests/typecheck/prog001/typecheck.prog001 + testsuite/tests/typecheck/should_compile/tc126 + testsuite/tests/typecheck/should_compile/T7903 + testsuite/tests/typecheck/should_compile/tc116 + testsuite/tests/typecheck/should_compile/tc175 + testsuite/tests/typecheck/should_compile/HasKey + testsuite/tests/typecheck/should_compile/tc125 + testsuite/tests/typecheck/should_compile/tc078 + testsuite/tests/typecheck/should_compile/tc161 + testsuite/tests/typecheck/should_fail/T5051 + testsuite/tests/typecheck/should_fail/T21583 + testsuite/tests/backpack/should_compile/bkp47 + testsuite/tests/backpack/should_fail/bkpfail25 + testsuite/tests/parser/should_compile/T2245 + testsuite/tests/parser/should_compile/read014 + testsuite/tests/indexed-types/should_compile/Class3 + testsuite/tests/indexed-types/should_compile/Simple2 + testsuite/tests/indexed-types/should_fail/T7862 + testsuite/tests/deriving/should_compile/deriving-1935 + testsuite/tests/deriving/should_compile/T9968a + testsuite/tests/deriving/should_compile/drv003 + testsuite/tests/deriving/should_compile/T4966 + testsuite/tests/deriving/should_compile/T14094 + testsuite/tests/perf/compiler/T15304 + testsuite/tests/warnings/minimal/WarnMinimal + testsuite/tests/simplCore/should_compile/simpl020 + testsuite/tests/deSugar/should_compile/T14546d + testsuite/tests/ghci/scripts/T5820 + testsuite/tests/ghci/scripts/ghci019 + -} + TcRnUnsatisfiedMinimalDef :: ClassMinimalDef -> TcRnMessage + + {- | 'TcRnMisplacedInstSig' is an error that happens when a method in + a class instance is given a type signature, but the user has not + enabled the @InstanceSigs@ extension. + + Test case: + testsuite/tests/module/mod45 + -} + TcRnMisplacedInstSig :: Name -> (LHsSigType GhcRn) -> TcRnMessage + {- | 'TcRnBadBootFamInstDecl' is an error that is triggered by a + type family instance being declared in an hs-boot file. + + Test case: + testsuite/tests/indexed-types/should_fail/HsBootFam + -} + TcRnBadBootFamInstDecl :: {} -> TcRnMessage + {- | 'TcRnIllegalFamilyInstance' is an error that occurs when an associated + type or data family is given a top-level instance. + + Test case: + testsuite/tests/indexed-types/should_fail/T3092 + -} + TcRnIllegalFamilyInstance :: TyCon -> TcRnMessage + {- | 'TcRnMissingClassAssoc' is an error that occurs when a class instance + for a class with an associated type or data family is missing a corresponding + family instance declaration. + + Test case: + testsuite/tests/indexed-types/should_fail/SimpleFail7 + -} + TcRnMissingClassAssoc :: TyCon -> TcRnMessage + {- | 'TcRnBadFamInstDecl' is an error that is triggered by a type or data family + instance without the @TypeFamilies@ extension. + + Test case: + testsuite/tests/indexed-types/should_fail/BadFamInstDecl + -} + TcRnBadFamInstDecl :: TyCon -> TcRnMessage + {- | 'TcRnNotOpenFamily' is an error that is triggered by attempting to give + a top-level (open) type family instance for a closed type family. + + Test cases: + testsuite/tests/indexed-types/should_fail/Overlap7 + testsuite/tests/indexed-types/should_fail/Overlap3 + -} + TcRnNotOpenFamily :: TyCon -> TcRnMessage + deriving Generic -- | Things forbidden in @type data@ declarations. |