diff options
author | Aaron Allen <aaron@flipstone.com> | 2021-06-06 14:57:46 -0500 |
---|---|---|
committer | Marge Bot <ben+marge-bot@smart-cactus.org> | 2021-06-23 20:33:48 -0400 |
commit | 8191785ed7a28ed7a797990ce8851034162d68bd (patch) | |
tree | 3992e293a67d558760e8b7e440822922b7fb0d44 | |
parent | 633bbc1fd4762a2bb73ba1c5b9e0c279f1dd3c40 (diff) | |
download | haskell-8191785ed7a28ed7a797990ce8851034162d68bd.tar.gz |
Converts diagnostics for two errors in Ghc.Tc.Module (#19926)
This adds constructors to TcRnMessage to replace use of
TcRnUnknownMessage in Ghc.Tc.Module.
Adds a test case for the UnsafeDueToPlugin warning.
Closes #19926
-rw-r--r-- | compiler/GHC/Tc/Errors/Ppr.hs | 12 | ||||
-rw-r--r-- | compiler/GHC/Tc/Errors/Types.hs | 11 | ||||
-rw-r--r-- | compiler/GHC/Tc/Module.hs | 9 | ||||
-rw-r--r-- | testsuite/tests/plugins/Makefile | 5 | ||||
-rw-r--r-- | testsuite/tests/plugins/T19926.hs | 5 | ||||
-rw-r--r-- | testsuite/tests/plugins/T19926.stderr | 5 | ||||
-rw-r--r-- | testsuite/tests/plugins/all.T | 6 | ||||
-rw-r--r-- | testsuite/tests/plugins/simple-plugin/Simple/DefaultPlugin.hs | 5 | ||||
-rw-r--r-- | testsuite/tests/plugins/simple-plugin/simple-plugin.cabal | 1 |
9 files changed, 52 insertions, 7 deletions
diff --git a/compiler/GHC/Tc/Errors/Ppr.hs b/compiler/GHC/Tc/Errors/Ppr.hs index d538862e50..578c182a7d 100644 --- a/compiler/GHC/Tc/Errors/Ppr.hs +++ b/compiler/GHC/Tc/Errors/Ppr.hs @@ -38,6 +38,10 @@ instance Diagnostic TcRnMessage where -> mkDecorated [ text "The import item" <+> quotes (ppr ie) <+> text "does not have an explicit import list" ] + TcRnUnsafeDueToPlugin + -> mkDecorated [text "Use of plugins makes the module unsafe"] + TcRnModMissingRealSrcSpan mod + -> mkDecorated [text "Module does not have a RealSrcSpan:" <+> ppr mod] diagnosticReason = \case TcRnUnknownMessage m @@ -54,6 +58,10 @@ instance Diagnostic TcRnMessage where -> WarningWithFlag Opt_WarnDodgyExports TcRnMissingImportList{} -> WarningWithFlag Opt_WarnMissingImportList + TcRnUnsafeDueToPlugin{} + -> WarningWithoutFlag + TcRnModMissingRealSrcSpan{} + -> ErrorWithoutFlag diagnosticHints = \case TcRnUnknownMessage m @@ -70,6 +78,10 @@ instance Diagnostic TcRnMessage where -> noHints TcRnMissingImportList{} -> noHints + TcRnUnsafeDueToPlugin{} + -> noHints + TcRnModMissingRealSrcSpan{} + -> noHints dodgy_msg :: (Outputable a, Outputable b) => SDoc -> a -> b -> SDoc dodgy_msg kind tc ie diff --git a/compiler/GHC/Tc/Errors/Types.hs b/compiler/GHC/Tc/Errors/Types.hs index b0deeaaf2c..4e9d233a67 100644 --- a/compiler/GHC/Tc/Errors/Types.hs +++ b/compiler/GHC/Tc/Errors/Types.hs @@ -11,6 +11,7 @@ import GHC.Hs import GHC.Types.Error import GHC.Types.Name (Name) import GHC.Types.Name.Reader +import GHC.Unit.Types (Module) import GHC.Utils.Outputable import Data.Typeable import GHC.Core.Type (Type, Var) @@ -88,6 +89,16 @@ data TcRnMessage where Test cases: rename/should_compile/T4489 -} TcRnMissingImportList :: IE GhcPs -> TcRnMessage + {-| When a module marked trustworthy or unsafe (using -XTrustworthy or -XUnsafe) is compiled + with a plugin, the TcRnUnsafeDueToPlugin warning (controlled by -Wunsafe) is used as the + reason the module was inferred to be unsafe. This warning is not raised if the + -fplugin-trustworthy flag is passed. + -} + TcRnUnsafeDueToPlugin :: TcRnMessage + {-| TcRnModMissingRealSrcSpan is an error that occurrs when compiling a module that lacks + an associated 'RealSrcSpan'. + -} + TcRnModMissingRealSrcSpan :: Module -> TcRnMessage -- | Where the levity checking for the input type originated diff --git a/compiler/GHC/Tc/Module.hs b/compiler/GHC/Tc/Module.hs index 56c3071ea5..08d082ba32 100644 --- a/compiler/GHC/Tc/Module.hs +++ b/compiler/GHC/Tc/Module.hs @@ -214,8 +214,7 @@ tcRnModule hsc_env mod_sum save_rn_syntax logger = hsc_logger hsc_env home_unit = hsc_home_unit hsc_env err_msg = mkPlainErrorMsgEnvelope loc $ - TcRnUnknownMessage $ mkPlainError noHints $ - text "Module does not have a RealSrcSpan:" <+> ppr this_mod + TcRnModMissingRealSrcSpan this_mod pair :: (Module, SrcSpan) pair@(this_mod,_) @@ -3151,10 +3150,6 @@ mark_plugin_unsafe :: DynFlags -> TcM () mark_plugin_unsafe dflags = unless (gopt Opt_PluginTrustworthy dflags) $ recordUnsafeInfer pluginUnsafe where - unsafeText = "Use of plugins makes the module unsafe" pluginUnsafe = singleMessage $ - mkPlainMsgEnvelope dflags noSrcSpan $ - TcRnUnknownMessage $ - mkPlainDiagnostic WarningWithoutFlag noHints $ - Outputable.text unsafeText + mkPlainMsgEnvelope dflags noSrcSpan TcRnUnsafeDueToPlugin diff --git a/testsuite/tests/plugins/Makefile b/testsuite/tests/plugins/Makefile index 46ef8cb3eb..2ae8aadae2 100644 --- a/testsuite/tests/plugins/Makefile +++ b/testsuite/tests/plugins/Makefile @@ -131,6 +131,11 @@ T16260: "$(TEST_HC)" $(TEST_HC_OPTS) $(ghcPluginWayFlags) -v0 T16260.hs -package-db simple-plugin/pkg.T16260/local.package.conf -fplugin Simple.TrustworthyPlugin "$(TEST_HC)" $(TEST_HC_OPTS) $(ghcPluginWayFlags) -v0 T16260.hs -package-db simple-plugin/pkg.T16260/local.package.conf -fplugin Simple.TrustworthyPlugin -fplugin-trustworthy +.PHONY: T19926 +T19926: + "$(TEST_HC)" $(TEST_HC_OPTS) $(ghcPluginWayFlags) -v0 T19926.hs -package-db simple-plugin/pkg.T19926/local.package.conf -fplugin Simple.DefaultPlugin + "$(TEST_HC)" $(TEST_HC_OPTS) $(ghcPluginWayFlags) -v0 T19926.hs -package-db simple-plugin/pkg.T19926/local.package.conf -fplugin Simple.DefaultPlugin -fplugin-trustworthy + .PHONY: HoleFitPlugin HoleFitPlugin: "$(TEST_HC)" $(TEST_HC_OPTS) $(ghcPluginWayFlags) -v0 HoleFitPlugin.hs -package-db hole-fit-plugin/pkg.hole-fit-plugin/local.package.conf diff --git a/testsuite/tests/plugins/T19926.hs b/testsuite/tests/plugins/T19926.hs new file mode 100644 index 0000000000..059611be05 --- /dev/null +++ b/testsuite/tests/plugins/T19926.hs @@ -0,0 +1,5 @@ +{-# LANGUAGE Haskell2010 #-} +{-# LANGUAGE Trustworthy #-} +{-# OPTIONS_GHC -Wunsafe #-} +module T19926 where +-- Trustworthy module compiled with plugin should warn if -fplugin-trustworthy is not set diff --git a/testsuite/tests/plugins/T19926.stderr b/testsuite/tests/plugins/T19926.stderr new file mode 100644 index 0000000000..e943a7ffba --- /dev/null +++ b/testsuite/tests/plugins/T19926.stderr @@ -0,0 +1,5 @@ + +T19926.hs:3:17: warning: [-Wunsafe] + ‘T19926’ has been inferred as unsafe! + Reason: + <no location info>: warning: Use of plugins makes the module unsafe diff --git a/testsuite/tests/plugins/all.T b/testsuite/tests/plugins/all.T index 12aba63022..7e8dbb52ef 100644 --- a/testsuite/tests/plugins/all.T +++ b/testsuite/tests/plugins/all.T @@ -208,6 +208,12 @@ test('T16260', ], makefile_test, []) +test('T19926', + [extra_files(['simple-plugin/']), + pre_cmd('$MAKE -s --no-print-directory -C simple-plugin package.T19926 TOP={top}') + ], + makefile_test, []) + test('test-hole-plugin', [extra_files(['hole-fit-plugin/']), pre_cmd('$MAKE -s --no-print-directory -C hole-fit-plugin package.hole-fit-plugin TOP={top}'), diff --git a/testsuite/tests/plugins/simple-plugin/Simple/DefaultPlugin.hs b/testsuite/tests/plugins/simple-plugin/Simple/DefaultPlugin.hs new file mode 100644 index 0000000000..6edf122376 --- /dev/null +++ b/testsuite/tests/plugins/simple-plugin/Simple/DefaultPlugin.hs @@ -0,0 +1,5 @@ +module Simple.DefaultPlugin (plugin) where +import GHC.Driver.Plugins (Plugin, defaultPlugin) + +plugin :: Plugin +plugin = defaultPlugin diff --git a/testsuite/tests/plugins/simple-plugin/simple-plugin.cabal b/testsuite/tests/plugins/simple-plugin/simple-plugin.cabal index e6f367100c..af68c5ca3b 100644 --- a/testsuite/tests/plugins/simple-plugin/simple-plugin.cabal +++ b/testsuite/tests/plugins/simple-plugin/simple-plugin.cabal @@ -21,3 +21,4 @@ Library Simple.SourcePlugin Simple.RemovePlugin Simple.TrustworthyPlugin + Simple.DefaultPlugin |