diff options
author | Torsten Schmits <git@tryp.io> | 2023-05-05 17:18:17 +0200 |
---|---|---|
committer | Marge Bot <ben+marge-bot@smart-cactus.org> | 2023-05-08 21:41:51 -0400 |
commit | 78c8dc509eacef5a5f09601b6bd004e13ae3a4c3 (patch) | |
tree | 729e7449fe02c7e3acec453112820e662638fc19 | |
parent | 3e3a6be4023189b2d637beda240e23fa9e856810 (diff) | |
download | haskell-78c8dc509eacef5a5f09601b6bd004e13ae3a4c3.tar.gz |
Add structured error messages for GHC.IfaceToCore
Tracking ticket: #20114
MR: !10390
This converts uses of `mkTcRnUnknownMessage` to newly added constructors
of `TcRnMessage`.
-rw-r--r-- | compiler/GHC/Iface/Errors/Ppr.hs | 7 | ||||
-rw-r--r-- | compiler/GHC/Iface/Errors/Types.hs | 1 | ||||
-rw-r--r-- | compiler/GHC/IfaceToCore.hs | 7 | ||||
-rw-r--r-- | compiler/GHC/Types/Error/Codes.hs | 1 |
4 files changed, 10 insertions, 6 deletions
diff --git a/compiler/GHC/Iface/Errors/Ppr.hs b/compiler/GHC/Iface/Errors/Ppr.hs index 031e4fd75c..3b260efcb4 100644 --- a/compiler/GHC/Iface/Errors/Ppr.hs +++ b/compiler/GHC/Iface/Errors/Ppr.hs @@ -65,6 +65,8 @@ interfaceErrorHints = \ case missingInterfaceErrorHints err Can'tFindNameInInterface {} -> noHints + CircularImport {} -> + noHints missingInterfaceErrorHints :: MissingInterfaceError -> [GhcHint] missingInterfaceErrorHints = \case @@ -86,6 +88,8 @@ interfaceErrorReason (Can'tFindInterface err _) = missingInterfaceErrorReason err interfaceErrorReason (Can'tFindNameInInterface {}) = ErrorWithoutFlag +interfaceErrorReason (CircularImport {}) + = ErrorWithoutFlag missingInterfaceErrorReason :: MissingInterfaceError -> DiagnosticReason missingInterfaceErrorReason = \ case @@ -287,6 +291,9 @@ interfaceErrorDiagnostic opts = \ case LookingForSig sig -> hang (text "Could not find interface file for signature" <+> quotes (ppr sig) <> colon) 2 (missingInterfaceErrorDiagnostic opts err) + CircularImport mod -> + text "Circular imports: module" <+> quotes (ppr mod) + <+> text "depends on itself" readInterfaceErrorDiagnostic :: ReadInterfaceError -> SDoc readInterfaceErrorDiagnostic = \ case diff --git a/compiler/GHC/Iface/Errors/Types.hs b/compiler/GHC/Iface/Errors/Types.hs index a421c2eeb7..50ccf6ba32 100644 --- a/compiler/GHC/Iface/Errors/Types.hs +++ b/compiler/GHC/Iface/Errors/Types.hs @@ -45,6 +45,7 @@ data IfaceMessage | Can'tFindNameInInterface Name [TyThing] -- possibly relevant TyThings + | CircularImport !Module deriving Generic data MissingInterfaceError diff --git a/compiler/GHC/IfaceToCore.hs b/compiler/GHC/IfaceToCore.hs index 2a81b9c2a0..e37f34ef46 100644 --- a/compiler/GHC/IfaceToCore.hs +++ b/compiler/GHC/IfaceToCore.hs @@ -605,7 +605,7 @@ tcHiBootIface hsc_src mod (LookingForHiBoot mod) in failWithTc (TcRnInterfaceError diag) -- The hi-boot file has mysteriously disappeared. - NotBoot -> failWithTc (mkTcRnUnknownMessage $ mkPlainError noHints moduleLoop) + NotBoot -> failWithTc (TcRnInterfaceError (CircularImport mod)) -- Someone below us imported us! -- This is a loop with no hi-boot in the way }}}} @@ -613,11 +613,6 @@ tcHiBootIface hsc_src mod need = text "Need the hi-boot interface for" <+> ppr mod <+> text "to compare against the Real Thing" - moduleLoop = text "Circular imports: module" <+> quotes (ppr mod) - <+> text "depends on itself" - - - mkSelfBootInfo :: ModIface -> ModDetails -> TcRn SelfBootInfo mkSelfBootInfo iface mds = do -- NB: This is computed DIRECTLY from the ModIface rather diff --git a/compiler/GHC/Types/Error/Codes.hs b/compiler/GHC/Types/Error/Codes.hs index 33cdd696f3..5025ff022f 100644 --- a/compiler/GHC/Types/Error/Codes.hs +++ b/compiler/GHC/Types/Error/Codes.hs @@ -719,6 +719,7 @@ type family GhcDiagnosticCode c = n | n -> c where GhcDiagnosticCode "NoUnitIdMatching" = 51294 GhcDiagnosticCode "NotAModule" = 35235 GhcDiagnosticCode "Can'tFindNameInInterface" = 83249 + GhcDiagnosticCode "CircularImport" = 75429 GhcDiagnosticCode "HiModuleNameMismatchWarn" = 53693 GhcDiagnosticCode "ExceptionOccurred" = 47808 |