Commit 91c15d65 authored by David Terei's avatar David Terei

Better error messages for new per-instance overlap flags and Safe

Haskell.
parent c79cbacb
......@@ -1025,13 +1025,21 @@ markUnsafe tcg_env whyUnsafe = do
whyUnsafe' df = vcat [ quotes pprMod <+> text "has been inferred as unsafe!"
, text "Reason:"
, nest 4 $ (vcat $ badFlags df) $+$
(vcat $ pprErrMsgBagWithLoc whyUnsafe)
(vcat $ pprErrMsgBagWithLoc whyUnsafe) $+$
(vcat $ badInsts $ tcg_insts tcg_env)
]
badFlags df = concat $ map (badFlag df) unsafeFlagsForInfer
badFlag df (str,loc,on,_)
| on df = [mkLocMessage SevOutput (loc df) $
text str <+> text "is not allowed in Safe Haskell"]
| otherwise = []
badInsts insts = concat $ map badInst insts
badInst ins | overlapMode (is_flag ins) /= NoOverlap
= [mkLocMessage SevOutput (nameSrcSpan $ getName $ is_dfun ins) $
ppr (overlapMode $ is_flag ins) <+>
text "overlap mode isn't allowed in Safe Haskell"]
| otherwise = []
-- | Figure out the final correct safe haskell mode
hscGetSafeMode :: TcGblEnv -> Hsc SafeHaskellMode
......
......@@ -2,6 +2,8 @@
UnsafeInfered13.hs:1:16: Warning:
‘UnsafeInfered13’ has been inferred as unsafe!
Reason:
UnsafeInfered13.hs:8:27:
[overlap ok] overlap mode isn't allowed in Safe Haskell
<no location info>:
Failing due to -Werror.
......@@ -2,6 +2,8 @@
UnsafeInfered14.hs:1:16: Warning:
‘UnsafeInfered14’ has been inferred as unsafe!
Reason:
UnsafeInfered14.hs:8:31:
[overlappable] overlap mode isn't allowed in Safe Haskell
<no location info>:
Failing due to -Werror.
......@@ -2,6 +2,8 @@
UnsafeInfered15.hs:1:16: Warning:
‘UnsafeInfered15’ has been inferred as unsafe!
Reason:
UnsafeInfered15.hs:8:30:
[overlapping] overlap mode isn't allowed in Safe Haskell
<no location info>:
Failing due to -Werror.
{-# OPTIONS_GHC -fwarn-unsafe -Werror #-}
{-# LANGUAGE FlexibleInstances #-}
module UnsafeInfered15 where
class C a where
f :: a -> String
instance {-# OVERLAPPING #-} C a where
f _ = "a"
instance {-# OVERLAPS #-} C Int where
f _ = "Int"
instance {-# OVERLAPPABLE #-} C Bool where
f _ = "Bool"
UnsafeInfered16.hs:1:16: Warning:
‘UnsafeInfered15’ has been inferred as unsafe!
Reason:
UnsafeInfered16.hs:8:30:
[overlapping] overlap mode isn't allowed in Safe Haskell
UnsafeInfered16.hs:11:27:
[overlap ok] overlap mode isn't allowed in Safe Haskell
UnsafeInfered16.hs:14:31:
[overlappable] overlap mode isn't allowed in Safe Haskell
<no location info>:
Failing due to -Werror.
......@@ -63,6 +63,7 @@ test('UnsafeInfered12', normal, compile_fail, [''])
test('UnsafeInfered13', normal, compile_fail, [''])
test('UnsafeInfered14', normal, compile_fail, [''])
test('UnsafeInfered15', normal, compile_fail, [''])
test('UnsafeInfered16', normal, compile_fail, [''])
# Mixed tests
test('Mixed01', normal, compile_fail, [''])
......
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