diff options
author | Simon Peyton Jones <simonpj@microsoft.com> | 2014-01-07 12:21:28 +0000 |
---|---|---|
committer | Simon Peyton Jones <simonpj@microsoft.com> | 2014-01-09 18:00:33 +0000 |
commit | 91252ef0f0d3c132b3006db7ca76999a72af3acd (patch) | |
tree | 15df67cd9ab355319426566bdacb964d9eeedcdb /testsuite | |
parent | b014797dc7c098af8e03d3aee24acaef36122cca (diff) | |
download | haskell-91252ef0f0d3c132b3006db7ca76999a72af3acd.tar.gz |
Test Trac #5498
Diffstat (limited to 'testsuite')
-rw-r--r-- | testsuite/tests/deriving/should_fail/T5498.hs | 41 | ||||
-rw-r--r-- | testsuite/tests/deriving/should_fail/T5498.stderr | 1 | ||||
-rw-r--r-- | testsuite/tests/deriving/should_fail/all.T | 1 |
3 files changed, 43 insertions, 0 deletions
diff --git a/testsuite/tests/deriving/should_fail/T5498.hs b/testsuite/tests/deriving/should_fail/T5498.hs new file mode 100644 index 0000000000..f267e14c14 --- /dev/null +++ b/testsuite/tests/deriving/should_fail/T5498.hs @@ -0,0 +1,41 @@ +{-# LANGUAGE GeneralizedNewtypeDeriving #-} +-- | We use newtype to create an isomorphic type to Int +-- with a reversed Ord dictionary. We now use the MinList +-- API of MinList to create a new MinList. Then we use newtype +-- deriving to convert the newtype MinList to an Int +-- MinList. This final result breaks the invariants of +-- MinList which shouldn't be possible with the exposed +-- API of MinList. +module T5498 where + +data MinList a = MinList a [a] + +newMinList :: Ord a => a -> MinList a +newMinList n = MinList n [] + +insertMinList :: Ord a => MinList a -> a -> MinList a +insertMinList s@(MinList m xs) n | n > m = MinList m (n:xs) + | otherwise = s + +printIntMinList :: MinList Int -> IO () +printIntMinList (MinList min xs) + = putStrLn $ "MinList Int :: MinList " ++ show min ++ " " ++ show xs + +class IntIso t where + intIso :: c t -> c Int + +instance IntIso Int where + intIso = id + +newtype Down a = Down a deriving (Eq, IntIso) + +instance Ord a => Ord (Down a) where + compare (Down a) (Down b) = compare b a + +fine :: MinList (Down Int) +fine = foldl (\x y -> insertMinList x $ Down y) + (newMinList $ Down 0) [-1,-2,-3,-4,1,2,3,4] + +bad :: MinList Int +bad = intIso fine + diff --git a/testsuite/tests/deriving/should_fail/T5498.stderr b/testsuite/tests/deriving/should_fail/T5498.stderr new file mode 100644 index 0000000000..0519ecba6e --- /dev/null +++ b/testsuite/tests/deriving/should_fail/T5498.stderr @@ -0,0 +1 @@ +
\ No newline at end of file diff --git a/testsuite/tests/deriving/should_fail/all.T b/testsuite/tests/deriving/should_fail/all.T index 8b90e7438f..b2b99ff997 100644 --- a/testsuite/tests/deriving/should_fail/all.T +++ b/testsuite/tests/deriving/should_fail/all.T @@ -47,3 +47,4 @@ test('T4846', normal, compile_fail, ['']) test('T7148', normal, compile_fail, ['']) test('T7148a', normal, compile_fail, ['']) test('T7800', normal, multimod_compile_fail, ['T7800','']) +test('T5498', normal, compile_fail, ['']) |