Commit fbd0586e authored by David Terei's avatar David Terei
Browse files

Infer safety of modules correctly with new overlapping pragmas.

parent 105602f4
......@@ -424,6 +424,7 @@ tcInstDecls1 tycl_decls inst_decls deriv_decls
; when (safeInferOn dflags) $ forM_ local_infos $ \x -> case x of
_ | typInstCheck x -> recordUnsafeInfer
_ | genInstCheck x -> recordUnsafeInfer
_ | overlapCheck x -> recordUnsafeInfer
_ -> return ()
; return ( gbl_env
......@@ -450,6 +451,8 @@ tcInstDecls1 tycl_decls inst_decls deriv_decls
ptext (sLit "Replace the following instance:"))
2 (pprInstanceHdr (iSpec i))
overlapCheck ty = overlapMode (is_flag $ iSpec ty) `elem`
[Overlappable, Overlapping, Overlaps]
genInstCheck ty = is_cls_nm (iSpec ty) `elem` genericClassNames
genInstErr i = hang (ptext (sLit $ "Generic instances can only be "
++ "derived in Safe Haskell.") $+$
......
{-# OPTIONS_GHC -fwarn-unsafe -Werror #-}
{-# LANGUAGE FlexibleInstances #-}
module UnsafeInfered13 where
class C a where
f :: a -> String
instance {-# OVERLAPS #-} C a where
f _ = "a"
{-# OPTIONS_GHC -fwarn-unsafe -Werror #-}
{-# LANGUAGE FlexibleInstances #-}
module UnsafeInfered14 where
class C a where
f :: a -> String
instance {-# OVERLAPPABLE #-} C a where
f _ = "a"
{-# OPTIONS_GHC -fwarn-unsafe -Werror #-}
{-# LANGUAGE FlexibleInstances #-}
module UnsafeInfered15 where
class C a where
f :: a -> String
instance {-# OVERLAPPING #-} C a where
f _ = "a"
......@@ -56,8 +56,11 @@ test('UnsafeInfered11',
[ extra_clean(['UnsafeInfered11_A.hi', 'UnsafeInfered11_A.o']) ],
multimod_compile_fail, ['UnsafeInfered11', ''])
# test should fail as unsafe and we made warn unsafe + -Werror
# Test should fail as unsafe and we made warn unsafe + -Werror
test('UnsafeInfered12', normal, compile_fail, [''])
test('UnsafeInfered13', normal, compile_fail, [''])
test('UnsafeInfered14', normal, compile_fail, [''])
test('UnsafeInfered15', 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