Commit b6c61e37 authored by Herbert Valerio Riedel's avatar Herbert Valerio Riedel 🕺
Browse files

Print which flag controls emitted SafeHaskell warnings

This is extends bb5afd3c to cover
SafeHaskell warnings.

This implements yet another part of #10752
parent 82f200b7
......@@ -450,12 +450,16 @@ tcRnModule' hsc_env sum save_rn_syntax mod = do
safe <- liftIO $ fst <$> readIORef (tcg_safeInfer tcg_res')
when safe $ do
case wopt Opt_WarnSafe dflags of
True -> (logWarnings $ unitBag $ mkPlainWarnMsg dflags
(warnSafeOnLoc dflags) $ errSafe tcg_res')
True -> (logWarnings $ unitBag $
makeIntoWarning (Reason Opt_WarnSafe) $
mkPlainWarnMsg dflags (warnSafeOnLoc dflags) $
errSafe tcg_res')
False | safeHaskell dflags == Sf_Trustworthy &&
wopt Opt_WarnTrustworthySafe dflags ->
(logWarnings $ unitBag $ mkPlainWarnMsg dflags
(trustworthyOnLoc dflags) $ errTwthySafe tcg_res')
(logWarnings $ unitBag $
makeIntoWarning (Reason Opt_WarnTrustworthySafe) $
mkPlainWarnMsg dflags (trustworthyOnLoc dflags) $
errTwthySafe tcg_res')
False -> return ()
return tcg_res'
where
......@@ -1095,7 +1099,7 @@ markUnsafeInfer tcg_env whyUnsafe = do
dflags <- getDynFlags
when (wopt Opt_WarnUnsafe dflags)
(logWarnings $ unitBag $
(logWarnings $ unitBag $ makeIntoWarning (Reason Opt_WarnUnsafe) $
mkPlainWarnMsg dflags (warnUnsafeOnLoc dflags) (whyUnsafe' dflags))
liftIO $ writeIORef (tcg_safeInfer tcg_env) (False, whyUnsafe)
......
SafeFlags22.hs:1:16: Warning:
SafeFlags22.hs:1:16: warning: [-Wunsafe]
‘SafeFlags22’ has been inferred as unsafe!
Reason:
SafeFlags22.hs:7:1:
SafeFlags22.hs:7:1: error:
System.IO.Unsafe: Can't be safely imported!
The module itself isn't safe.
SafeFlags23.hs:1:16: Warning:
SafeFlags23.hs:1:16: warning: [-Wunsafe]
‘SafeFlags22’ has been inferred as unsafe!
Reason:
SafeFlags23.hs:7:1:
SafeFlags23.hs:7:1: error:
System.IO.Unsafe: Can't be safely imported!
The module itself isn't safe.
<no location info>:
<no location info>: error:
Failing due to -Werror.
SafeFlags25.hs:1:16: Warning:
SafeFlags25.hs:1:16: warning: [-Wsafe]
‘SafeFlags25’ has been inferred as safe!
SafeFlags26.hs:1:16: Warning:
SafeFlags26.hs:1:16: warning: [-Wsafe]
‘SafeFlags26’ has been inferred as safe!
<no location info>:
<no location info>: error:
Failing due to -Werror.
......@@ -2,17 +2,18 @@
[2 of 3] Compiling SH_Overlap11_A ( SH_Overlap11_A.hs, SH_Overlap11_A.o )
[3 of 3] Compiling SH_Overlap11 ( SH_Overlap11.hs, SH_Overlap11.o )
SH_Overlap11.hs:1:16: warning:
SH_Overlap11.hs:1:16: warning: [-Wunsafe]
‘SH_Overlap11’ has been inferred as unsafe!
Reason:
SH_Overlap11.hs:17:8: warning:
Unsafe overlapping instances for C [Int] arising from a use of ‘f’
The matching instance is:
instance [overlap ok] [safe] C [Int]
-- Defined at SH_Overlap11_A.hs:11:3
It is compiled in a Safe module and as such can only
overlap instances from the same module, however it
overlaps the following instances from different modules:
instance C [a] -- Defined at SH_Overlap11.hs:13:3
In the expression: f ([1, 2, 3, 4] :: [Int])
In an equation for ‘test’: test = f ([1, 2, 3, 4] :: [Int])
• Unsafe overlapping instances for C [Int]
arising from a use of ‘f’
The matching instance is:
instance [overlap ok] [safe] C [Int]
-- Defined at SH_Overlap11_A.hs:11:3
It is compiled in a Safe module and as such can only
overlap instances from the same module, however it
overlaps the following instances from different modules:
instance C [a] -- Defined at SH_Overlap11.hs:13:3
• In the expression: f ([1, 2, 3, 4] :: [Int])
In an equation for ‘test’: test = f ([1, 2, 3, 4] :: [Int])
......@@ -2,20 +2,21 @@
[2 of 3] Compiling SH_Overlap7_A ( SH_Overlap7_A.hs, SH_Overlap7_A.o )
[3 of 3] Compiling SH_Overlap7 ( SH_Overlap7.hs, SH_Overlap7.o )
SH_Overlap7.hs:1:16: warning:
SH_Overlap7.hs:1:16: warning: [-Wunsafe]
‘SH_Overlap7’ has been inferred as unsafe!
Reason:
SH_Overlap7.hs:14:8: warning:
Unsafe overlapping instances for C [Int] arising from a use of ‘f’
The matching instance is:
instance [overlap ok] [safe] C [Int]
-- Defined at SH_Overlap7_A.hs:12:3
It is compiled in a Safe module and as such can only
overlap instances from the same module, however it
overlaps the following instances from different modules:
instance C [a] -- Defined at SH_Overlap7.hs:10:10
In the expression: f ([1, 2, 3, 4] :: [Int])
In an equation for ‘test’: test = f ([1, 2, 3, 4] :: [Int])
• Unsafe overlapping instances for C [Int]
arising from a use of ‘f’
The matching instance is:
instance [overlap ok] [safe] C [Int]
-- Defined at SH_Overlap7_A.hs:12:3
It is compiled in a Safe module and as such can only
overlap instances from the same module, however it
overlaps the following instances from different modules:
instance C [a] -- Defined at SH_Overlap7.hs:10:10
• In the expression: f ([1, 2, 3, 4] :: [Int])
In an equation for ‘test’: test = f ([1, 2, 3, 4] :: [Int])
<no location info>: error:
Failing due to -Werror.
......@@ -3,6 +3,6 @@ SafeInfered05.hs:2:14: warning:
-XOverlappingInstances is deprecated: instead use per-instance pragmas OVERLAPPING/OVERLAPPABLE/OVERLAPS
[1 of 2] Compiling SafeInfered05_A ( SafeInfered05_A.hs, SafeInfered05_A.o )
SafeInfered05_A.hs:2:16: warning:
SafeInfered05_A.hs:2:16: warning: [-Wsafe]
‘SafeInfered05_A’ has been inferred as safe!
[2 of 2] Compiling SafeInfered05 ( SafeInfered05.hs, SafeInfered05.o )
SafeWarn01.hs:2:16: Warning:
SafeWarn01.hs:2:16: warning: [-Wsafe]
‘SafeWarn01’ has been inferred as safe!
TrustworthySafe02.hs:1:14: Warning:
TrustworthySafe02.hs:1:14: warning: [-Wtrustworthy-safe (in -Wall)]
‘TrustworthySafe02’ is marked as Trustworthy but has been inferred as safe!
TrustworthySafe03.hs:1:14: Warning:
TrustworthySafe03.hs:1:14: warning: [-Wtrustworthy-safe (in -Wall)]
‘TrustworthySafe03’ is marked as Trustworthy but has been inferred as safe!
[1 of 2] Compiling UnsafeInfered11_A ( UnsafeInfered11_A.hs, UnsafeInfered11_A.o )
UnsafeInfered11_A.hs:1:16: Warning:
UnsafeInfered11_A.hs:1:16: warning: [-Wunsafe]
‘UnsafeInfered11_A’ has been inferred as unsafe!
Reason:
UnsafeInfered11_A.hs:17:11: Warning:
UnsafeInfered11_A.hs:17:11: warning:
Rule "lookupx/T" ignored
User defined rules are disabled under Safe Haskell
[2 of 2] Compiling UnsafeInfered11 ( UnsafeInfered11.hs, UnsafeInfered11.o )
UnsafeInfered11.hs:5:1:
UnsafeInfered11.hs:5:1: error:
UnsafeInfered11_A: Can't be safely imported!
The module itself isn't safe.
UnsafeInfered12.hs:2:16: Warning:
UnsafeInfered12.hs:2:16: warning: [-Wunsafe]
‘UnsafeInfered12’ has been inferred as unsafe!
Reason:
UnsafeInfered12.hs:1:14:
-XTemplateHaskell is not allowed in Safe Haskell
<no location info>:
<no location info>: error:
Failing due to -Werror.
UnsafeWarn01.hs:2:16: Warning:
UnsafeWarn01.hs:2:16: warning: [-Wunsafe]
‘UnsafeWarn01’ has been inferred as unsafe!
Reason:
UnsafeWarn01.hs:7:1:
UnsafeWarn01.hs:7:1: error:
System.IO.Unsafe: Can't be safely imported!
The module itself isn't safe.
UnsafeWarn02.hs:2:16: Warning:
UnsafeWarn02.hs:2:16: warning: [-Wunsafe]
‘UnsafeWarn02’ has been inferred as unsafe!
Reason:
UnsafeWarn02.hs:4:14:
......
UnsafeWarn03.hs:3:16: Warning:
UnsafeWarn03.hs:3:16: warning: [-Wunsafe]
‘UnsafeWarn03’ has been inferred as unsafe!
Reason:
UnsafeWarn03.hs:8:1:
UnsafeWarn03.hs:8:1: error:
System.IO.Unsafe: Can't be safely imported!
The module itself isn't safe.
UnsafeWarn04.hs:3:16: Warning:
UnsafeWarn04.hs:3:16: warning: [-Wunsafe]
‘UnsafeWarn04’ has been inferred as unsafe!
Reason:
UnsafeWarn04.hs:8:1:
UnsafeWarn04.hs:8:1: error:
System.IO.Unsafe: Can't be safely imported!
The module itself isn't safe.
UnsafeWarn05.hs:4:16: Warning:
UnsafeWarn05.hs:4:16: warning: [-Wunsafe]
‘UnsafeWarn05’ has been inferred as unsafe!
Reason:
UnsafeWarn05.hs:10:1:
UnsafeWarn05.hs:10:1: error:
System.IO.Unsafe: Can't be safely imported!
The module itself isn't safe.
UnsafeWarn05.hs:4:16: Warning:
UnsafeWarn05.hs:4:16: warning: [-Wunsafe]
‘UnsafeWarn05’ has been inferred as unsafe!
Reason:
UnsafeWarn05.hs:15:11: Warning:
UnsafeWarn05.hs:15:11: warning:
Rule "g" ignored
User defined rules are disabled under Safe Haskell
UnsafeWarn06.hs:3:16: Warning:
UnsafeWarn06.hs:3:16: warning: [-Wunsafe]
‘UnsafeWarn06’ has been inferred as unsafe!
Reason:
UnsafeWarn06.hs:8:11: Warning:
UnsafeWarn06.hs:8:11: warning:
Rule "f" ignored
User defined rules are disabled under Safe Haskell
UnsafeWarn07.hs:4:16: Warning:
UnsafeWarn07.hs:4:16: warning: [-Wunsafe]
‘UnsafeWarn07’ has been inferred as unsafe!
Reason:
UnsafeWarn07.hs:9:11: Warning:
UnsafeWarn07.hs:9:11: warning:
Rule "f" ignored
User defined rules are disabled under Safe Haskell
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment