diff options
author | Joachim Breitner <mail@joachim-breitner.de> | 2013-11-19 12:15:30 +0000 |
---|---|---|
committer | Joachim Breitner <mail@joachim-breitner.de> | 2013-11-19 12:15:30 +0000 |
commit | ea3c659e10ccc69bc4ae053a2e111abc672c3c4b (patch) | |
tree | 96c61f9fe860fb84a8853bfc1b1db0687c78b193 /testsuite/tests | |
parent | a37c6ad604e28c4f554e342ef8b967a2650829f9 (diff) | |
download | haskell-ea3c659e10ccc69bc4ae053a2e111abc672c3c4b.tar.gz |
Test coercing under under-saturated newtypes
Diffstat (limited to 'testsuite/tests')
-rw-r--r-- | testsuite/tests/typecheck/should_run/TcCoercible.hs | 20 | ||||
-rw-r--r-- | testsuite/tests/typecheck/should_run/TcCoercible.stdout | 1 |
2 files changed, 15 insertions, 6 deletions
diff --git a/testsuite/tests/typecheck/should_run/TcCoercible.hs b/testsuite/tests/typecheck/should_run/TcCoercible.hs index f5a3b9732b..4aa4ac111b 100644 --- a/testsuite/tests/typecheck/should_run/TcCoercible.hs +++ b/testsuite/tests/typecheck/should_run/TcCoercible.hs @@ -15,26 +15,34 @@ data Map a b = Map a b deriving Show newtype List a = List [a] deriving Show data T f = T (f Int) +-- It should be possible to coerce _under_ undersaturated newtypes +newtype NonEtad a b = NonEtad (Either b a) deriving Show + + + main = do print (coerce $ one :: Age) - print (coerce $ Age 1 :: Int) - print (coerce $ Baz (Bar (Age 1)) :: Foo) + print (coerce $ age :: Int) + print (coerce $ Baz (Bar age) :: Foo) - print (coerce (id::Bar->Bar) (Age 1) :: Foo) - print (coerce Baz (Age 1) :: Foo) - print (coerce $ (Age 1, Foo (Age 1)) :: (Baz, Baz)) + print (coerce (id::Bar->Bar) age :: Foo) + print (coerce Baz age :: Foo) + print (coerce $ (Age 1, Foo age) :: (Baz, Baz)) print (coerce $ Map one one :: Map Int Age) print (coerce $ Just one :: First Int) print (coerce $ (mempty :: Last Age) :: Last Int) - printT (coerce $ (T (Left (Age 1)) :: T (Either Age)) :: T (Either Int)) + printT (coerce $ (T (Left age) :: T (Either Age)) :: T (Either Int)) printT (coerce $ (T (Left one) :: T (Either Int)) :: T (Either Age)) printT (coerce $ (T [one] :: T []) :: T List) printT (coerce $ (T (List [one]) :: T List) :: T []) + printT (coerce $ (T (NonEtad (Right age)) :: T (NonEtad Age)) :: T (NonEtad Int)) + where one = 1 :: Int + age = Age one printT (T x) = print x diff --git a/testsuite/tests/typecheck/should_run/TcCoercible.stdout b/testsuite/tests/typecheck/should_run/TcCoercible.stdout index 5c92bf4c0d..687480454d 100644 --- a/testsuite/tests/typecheck/should_run/TcCoercible.stdout +++ b/testsuite/tests/typecheck/should_run/TcCoercible.stdout @@ -11,3 +11,4 @@ Left 1 Left (Age 1) List [1] [1] +NonEtad (Right 1) |