summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--compiler/GHC/Driver/Main.hs28
-rw-r--r--testsuite/tests/safeHaskell/warnings/Makefile3
-rw-r--r--testsuite/tests/safeHaskell/warnings/T22728.hs6
-rw-r--r--testsuite/tests/safeHaskell/warnings/T22728.stderr4
-rw-r--r--testsuite/tests/safeHaskell/warnings/T22728_B.hs6
-rw-r--r--testsuite/tests/safeHaskell/warnings/T22728b.hs6
-rw-r--r--testsuite/tests/safeHaskell/warnings/T22728b.stderr4
-rw-r--r--testsuite/tests/safeHaskell/warnings/T22728b_B.hs6
-rw-r--r--testsuite/tests/safeHaskell/warnings/all.T2
9 files changed, 52 insertions, 13 deletions
diff --git a/compiler/GHC/Driver/Main.hs b/compiler/GHC/Driver/Main.hs
index 976cf12b55..255ffaf035 100644
--- a/compiler/GHC/Driver/Main.hs
+++ b/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
diff --git a/testsuite/tests/safeHaskell/warnings/Makefile b/testsuite/tests/safeHaskell/warnings/Makefile
new file mode 100644
index 0000000000..9101fbd40a
--- /dev/null
+++ b/testsuite/tests/safeHaskell/warnings/Makefile
@@ -0,0 +1,3 @@
+TOP=../../..
+include $(TOP)/mk/boilerplate.mk
+include $(TOP)/mk/test.mk
diff --git a/testsuite/tests/safeHaskell/warnings/T22728.hs b/testsuite/tests/safeHaskell/warnings/T22728.hs
new file mode 100644
index 0000000000..bd24e88d6d
--- /dev/null
+++ b/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
diff --git a/testsuite/tests/safeHaskell/warnings/T22728.stderr b/testsuite/tests/safeHaskell/warnings/T22728.stderr
new file mode 100644
index 0000000000..310749eee2
--- /dev/null
+++ 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
diff --git a/testsuite/tests/safeHaskell/warnings/T22728_B.hs b/testsuite/tests/safeHaskell/warnings/T22728_B.hs
new file mode 100644
index 0000000000..2673100932
--- /dev/null
+++ b/testsuite/tests/safeHaskell/warnings/T22728_B.hs
@@ -0,0 +1,6 @@
+-- inferred safe
+{-# LANGUAGE Haskell2010 #-}
+module T22728_B where
+
+int :: Int
+int = 3
diff --git a/testsuite/tests/safeHaskell/warnings/T22728b.hs b/testsuite/tests/safeHaskell/warnings/T22728b.hs
new file mode 100644
index 0000000000..4580fdbeb8
--- /dev/null
+++ b/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
diff --git a/testsuite/tests/safeHaskell/warnings/T22728b.stderr b/testsuite/tests/safeHaskell/warnings/T22728b.stderr
new file mode 100644
index 0000000000..e1fc69da6c
--- /dev/null
+++ 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
diff --git a/testsuite/tests/safeHaskell/warnings/T22728b_B.hs b/testsuite/tests/safeHaskell/warnings/T22728b_B.hs
new file mode 100644
index 0000000000..882629c2f6
--- /dev/null
+++ b/testsuite/tests/safeHaskell/warnings/T22728b_B.hs
@@ -0,0 +1,6 @@
+-- inferred safe
+{-# LANGUAGE Haskell2010 #-}
+module T22728b_B where
+
+int :: Int
+int = 3
diff --git a/testsuite/tests/safeHaskell/warnings/all.T b/testsuite/tests/safeHaskell/warnings/all.T
new file mode 100644
index 0000000000..f32154d6c5
--- /dev/null
+++ b/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', '')], ''])