summaryrefslogtreecommitdiff
path: root/testsuite
diff options
context:
space:
mode:
authorsheaf <sam.derbyshire@gmail.com>2023-05-11 13:08:14 +0200
committerMarge Bot <ben+marge-bot@smart-cactus.org>2023-05-12 06:10:57 -0400
commitc176ad1835ccfe55e2bde875b4a35e9d226ff657 (patch)
tree585897cd4bdbb5babd5c86eaed88aa26a8a42595 /testsuite
parenta856d98eb13401b78fa7eba9a54ea4c501ebb0a2 (diff)
downloadhaskell-c176ad1835ccfe55e2bde875b4a35e9d226ff657.tar.gz
Don't panic in mkNewTyConRhs
This function could come across invalid newtype constructors, as we only perform validity checking of newtypes once we are outside the knot-tied typechecking loop. This patch changes this function to fake up a stub type in the case of an invalid newtype, instead of panicking. This patch also changes "checkNewDataCon" so that it reports as many errors as possible at once. Fixes #23308
Diffstat (limited to 'testsuite')
-rw-r--r--testsuite/tests/typecheck/should_fail/T23308.hs39
-rw-r--r--testsuite/tests/typecheck/should_fail/T23308.stderr50
-rw-r--r--testsuite/tests/typecheck/should_fail/all.T1
3 files changed, 90 insertions, 0 deletions
diff --git a/testsuite/tests/typecheck/should_fail/T23308.hs b/testsuite/tests/typecheck/should_fail/T23308.hs
new file mode 100644
index 0000000000..c5b55ee2d2
--- /dev/null
+++ b/testsuite/tests/typecheck/should_fail/T23308.hs
@@ -0,0 +1,39 @@
+{-# LANGUAGE DataKinds, UnliftedNewtypes, TypeFamilies #-}
+
+module T23308 where
+
+import Data.Proxy
+import GHC.Exts
+
+-- Check that we don't panic in the middle of typechecking
+-- when there is an invalid newtype in a knot-tied group of TyCons.
+
+data A1 = A1 !B1
+newtype B1 = B1 C1 C1
+data C1 = C1 A1
+
+
+data A2 = A2 !B2
+newtype B2 where { B2 :: forall (x :: C2). Proxy x -> B2 }
+data C2 = C2 A2
+
+type F2' :: forall {k}. k -> TYPE WordRep
+type family F2' a where {}
+data A2' = A2' !B2'
+newtype B2' where { B2' :: forall (x :: C2'). F2' x -> B2' }
+data C2' = C2' A2'
+
+
+data A3 = A3 !B3
+newtype B3 where { B3 :: forall (x :: C2). B2 }
+data C3 = C3 A3
+
+
+data A4 = A4 !(B4 Int)
+newtype B4 a where { B4 :: C4 -> B4 Int }
+data C4 = C4 A4
+
+
+data A5 = A5 !(B5 Int)
+newtype B5 a where { B5 :: Num a => B5 (a, a) }
+data C5 = C5 A5
diff --git a/testsuite/tests/typecheck/should_fail/T23308.stderr b/testsuite/tests/typecheck/should_fail/T23308.stderr
new file mode 100644
index 0000000000..299876def4
--- /dev/null
+++ b/testsuite/tests/typecheck/should_fail/T23308.stderr
@@ -0,0 +1,50 @@
+
+T23308.hs:12:14: error: [GHC-23517]
+ • A newtype constructor must have exactly one field
+ but ‘B1’ has two
+ B1 :: C1 -> C1 -> B1
+ • In the definition of data constructor ‘B1’
+ In the newtype declaration for ‘B1’
+
+T23308.hs:17:20: error: [GHC-07525]
+ • A newtype constructor must not have existential type variables
+ B2 :: forall (x :: C2). Proxy x -> B2
+ • In the definition of data constructor ‘B2’
+ In the newtype declaration for ‘B2’
+
+T23308.hs:23:21: error: [GHC-07525]
+ • A newtype constructor must not have existential type variables
+ B2' :: forall (x :: C2'). F2' x -> B2'
+ • In the definition of data constructor ‘B2'’
+ In the newtype declaration for ‘B2'’
+
+T23308.hs:28:20: error: [GHC-45219]
+ • Data constructor ‘B3’ returns type ‘B2’
+ instead of an instance of its parent type ‘B3’
+ • In the definition of data constructor ‘B3’
+ In the newtype declaration for ‘B3’
+
+T23308.hs:33:22: error: [GHC-89498]
+ • A newtype must not be a GADT
+ B4 :: C4 -> B4 Int
+ • In the definition of data constructor ‘B4’
+ In the newtype declaration for ‘B4’
+
+T23308.hs:38:22: error: [GHC-17440]
+ • A newtype constructor must not have a context in its type
+ B5 :: forall a. Num a => B5 (a, a)
+ • In the definition of data constructor ‘B5’
+ In the newtype declaration for ‘B5’
+
+T23308.hs:38:22: error: [GHC-89498]
+ • A newtype must not be a GADT
+ B5 :: forall a. Num a => B5 (a, a)
+ • In the definition of data constructor ‘B5’
+ In the newtype declaration for ‘B5’
+
+T23308.hs:38:22: error: [GHC-23517]
+ • A newtype constructor must have exactly one field
+ but ‘B5’ has none
+ B5 :: forall a. Num a => B5 (a, a)
+ • In the definition of data constructor ‘B5’
+ In the newtype declaration for ‘B5’
diff --git a/testsuite/tests/typecheck/should_fail/all.T b/testsuite/tests/typecheck/should_fail/all.T
index f62ee5e355..b6c4a0366d 100644
--- a/testsuite/tests/typecheck/should_fail/all.T
+++ b/testsuite/tests/typecheck/should_fail/all.T
@@ -676,6 +676,7 @@ test('PatSynExistential', normal, compile_fail, [''])
test('PatSynArity', normal, compile_fail, [''])
test('PatSynUnboundVar', normal, compile_fail, [''])
test('T21444', normal, compile_fail, [''])
+test('T23308', normal, compile_fail, [''])
test('MultiAssocDefaults', normal, compile_fail, [''])
test('LazyFieldsDisabled', normal, compile_fail, [''])
test('TyfamsDisabled', normal, compile_fail, [''])