[Git][ghc/ghc][master] Fix #22728: Not all diagnostics in safe check are fatal
Marge Bot (@marge-bot)
gitlab at gitlab.haskell.org
Thu Jan 12 20:54:44 UTC 2023
Marge Bot pushed to branch master at Glasgow Haskell Compiler / GHC
Commits:
1b812b69 by Oleg Grenrus at 2023-01-12T15:54:21-05:00
Fix #22728: Not all diagnostics in safe check are fatal
Also add tests for the issue and -Winferred-safe-imports in general
- - - - -
9 changed files:
- compiler/GHC/Driver/Main.hs
- + testsuite/tests/safeHaskell/warnings/Makefile
- + testsuite/tests/safeHaskell/warnings/T22728.hs
- + testsuite/tests/safeHaskell/warnings/T22728.stderr
- + testsuite/tests/safeHaskell/warnings/T22728_B.hs
- + testsuite/tests/safeHaskell/warnings/T22728b.hs
- + testsuite/tests/safeHaskell/warnings/T22728b.stderr
- + testsuite/tests/safeHaskell/warnings/T22728b_B.hs
- + testsuite/tests/safeHaskell/warnings/all.T
Changes:
=====================================
compiler/GHC/Driver/Main.hs
=====================================
@@ -1468,19 +1468,21 @@ checkSafeImports tcg_env
-- restore old errors
logDiagnostics oldErrs
- case (isEmptyMessages safeErrs) of
- -- Failed safe check
- False -> liftIO . throwErrors $ safeErrs
-
- -- Passed safe check
- True -> do
- let infPassed = isEmptyMessages infErrs
- tcg_env' <- case (not infPassed) of
- True -> markUnsafeInfer tcg_env infErrs
- False -> return tcg_env
- when (packageTrustOn dflags) $ checkPkgTrust pkgReqs
- let newTrust = pkgTrustReqs dflags safePkgs infPkgs infPassed
- return tcg_env' { tcg_imports = impInfo `plusImportAvails` newTrust }
+ diag_opts <- initDiagOpts <$> getDynFlags
+ print_config <- initPrintConfig <$> getDynFlags
+ logger <- getLogger
+
+ -- Will throw if failed safe check
+ liftIO $ printOrThrowDiagnostics logger print_config diag_opts safeErrs
+
+ -- No fatal warnings or errors: passed safe check
+ let infPassed = isEmptyMessages infErrs
+ tcg_env' <- case (not infPassed) of
+ True -> markUnsafeInfer tcg_env infErrs
+ False -> return tcg_env
+ when (packageTrustOn dflags) $ checkPkgTrust pkgReqs
+ let newTrust = pkgTrustReqs dflags safePkgs infPkgs infPassed
+ return tcg_env' { tcg_imports = impInfo `plusImportAvails` newTrust }
where
impInfo = tcg_imports tcg_env -- ImportAvails
=====================================
testsuite/tests/safeHaskell/warnings/Makefile
=====================================
@@ -0,0 +1,3 @@
+TOP=../../..
+include $(TOP)/mk/boilerplate.mk
+include $(TOP)/mk/test.mk
=====================================
testsuite/tests/safeHaskell/warnings/T22728.hs
=====================================
@@ -0,0 +1,6 @@
+{-# LANGUAGE Safe #-}
+{-# LANGUAGE Haskell2010 #-}
+{-# OPTIONS_GHC -Winferred-safe-imports #-}
+module T22728 (module T22728_B) where
+
+import T22728_B
=====================================
testsuite/tests/safeHaskell/warnings/T22728.stderr
=====================================
@@ -0,0 +1,4 @@
+[2 of 2] Compiling T22728 ( T22728.hs, T22728.o )
+
+T22728.hs:6:1: warning: [GHC-82658] [-Winferred-safe-imports]
+ Importing Safe-Inferred module T22728_B from explicitly Safe module
=====================================
testsuite/tests/safeHaskell/warnings/T22728_B.hs
=====================================
@@ -0,0 +1,6 @@
+-- inferred safe
+{-# LANGUAGE Haskell2010 #-}
+module T22728_B where
+
+int :: Int
+int = 3
=====================================
testsuite/tests/safeHaskell/warnings/T22728b.hs
=====================================
@@ -0,0 +1,6 @@
+{-# LANGUAGE Safe #-}
+{-# LANGUAGE Haskell2010 #-}
+{-# OPTIONS_GHC -Werror=inferred-safe-imports #-}
+module T22728b (module T22728b_B) where
+
+import T22728b_B
=====================================
testsuite/tests/safeHaskell/warnings/T22728b.stderr
=====================================
@@ -0,0 +1,4 @@
+[2 of 2] Compiling T22728b ( T22728b.hs, T22728b.o )
+
+T22728b.hs:6:1: error: [GHC-82658] [-Winferred-safe-imports, Werror=inferred-safe-imports]
+ Importing Safe-Inferred module T22728b_B from explicitly Safe module
=====================================
testsuite/tests/safeHaskell/warnings/T22728b_B.hs
=====================================
@@ -0,0 +1,6 @@
+-- inferred safe
+{-# LANGUAGE Haskell2010 #-}
+module T22728b_B where
+
+int :: Int
+int = 3
=====================================
testsuite/tests/safeHaskell/warnings/all.T
=====================================
@@ -0,0 +1,2 @@
+test('T22728', normal, multi_compile, ['T22728.hs', [('T22728_B.hs', '')], ''])
+test('T22728b', normal, multi_compile_fail, ['T22728b.hs', [('T22728b_B.hs', '')], ''])
View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/1b812b6973a25cb1962e2fc543d2c4ed3cf31f3c
--
View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/1b812b6973a25cb1962e2fc543d2c4ed3cf31f3c
You're receiving this email because of your account on gitlab.haskell.org.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.haskell.org/pipermail/ghc-commits/attachments/20230112/3614251e/attachment-0001.html>
More information about the ghc-commits
mailing list