Commit c96a613c authored by David Terei's avatar David Terei

Add in Incoherent Instances test for Safe Haskell.

parent 91c15d65
{-# OPTIONS_GHC -fwarn-unsafe -Werror #-}
{-# LANGUAGE FlexibleInstances #-}
module UnsafeInfered15 where
class C a where
f :: a -> String
instance {-# INCOHERENT #-} C a where
f _ = "a"
UnsafeInfered17.hs:1:16: Warning:
‘UnsafeInfered15’ has been inferred as unsafe!
Reason:
UnsafeInfered17.hs:8:29:
[incoherent] overlap mode isn't allowed in Safe Haskell
<no location info>:
Failing due to -Werror.
......@@ -64,6 +64,7 @@ test('UnsafeInfered13', normal, compile_fail, [''])
test('UnsafeInfered14', normal, compile_fail, [''])
test('UnsafeInfered15', normal, compile_fail, [''])
test('UnsafeInfered16', normal, compile_fail, [''])
test('UnsafeInfered17', normal, compile_fail, [''])
# Mixed tests
test('Mixed01', normal, compile_fail, [''])
......
{-# LANGUAGE Trustworthy #-}
module Main where
import SafeLang17_A -- trusted lib
import SafeLang17_B -- untrusted plugin
main = do
let r = res [(1::Int)]
putStrLn $ "Result: " ++ show r
putStrLn $ "Result: " ++ show function
[1 of 3] Compiling SafeLang17_A ( SafeLang17_A.hs, SafeLang17_A.o )
[2 of 3] Compiling SafeLang17_B ( SafeLang17_B.hs, SafeLang17_B.o )
[3 of 3] Compiling Main ( SafeLang17.hs, SafeLang17.o )
SafeLang17.hs:8:13:
Unsafe overlapping instances for Pos [Int]
arising from a use of ‘res’
The matching instance is:
instance [incoherent] [safe] Pos [Int]
-- Defined at SafeLang17_B.hs:14:10
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 Pos [a] -- Defined at SafeLang17_A.hs:13:10
In the expression: res [(1 :: Int)]
In an equation for ‘r’: r = res [(1 :: Int)]
In the expression:
do { let r = res ...;
putStrLn $ "Result: " ++ show r;
putStrLn $ "Result: " ++ show function }
{-# LANGUAGE Trustworthy #-}
{-# LANGUAGE FlexibleInstances #-}
-- | Trusted library that unsafe plugins can use
module SafeLang17_A where
class Pos a where
res :: a -> Bool
-- Any call to res with a list in out TCB
-- should use this method and never a more
-- specific one provided by an untrusted module
instance Pos [a] where
res _ = True
{-# LANGUAGE Safe #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE IncoherentInstances #-}
-- Untrusted plugin! Don't wan't it changing behaviour of our
-- trusted code
module SafeLang17_B where
import SafeLang17_A
instance Pos a where
res _ = False
instance Pos [Int] where
res _ = error "This curry is poisoned!"
function :: Int
function = 3
......@@ -45,6 +45,11 @@ test('SafeLang15',
multimod_compile_and_run,
['SafeLang15', '-XSafe'])
test('SafeLang16', normal, compile, [''])
test('SafeLang17',
extra_clean(['SafeLang17_A.o', 'SafeLang17_A.hi',
'SafeLang17_B.o', 'SafeLang17_B.hi']),
multimod_compile_fail,
['SafeLang17', ''])
# Test building a package, that trust values are set correctly
# and can be changed correctly
......
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