summaryrefslogtreecommitdiff
path: root/testsuite
diff options
context:
space:
mode:
authorRyan Scott <ryan.gl.scott@gmail.com>2022-12-09 09:17:42 -0500
committerMarge Bot <ben+marge-bot@smart-cactus.org>2022-12-15 03:56:26 -0500
commit03ed0b95147ef6da99ac60302fea282d4df5f072 (patch)
treeeec1ce74c7dd14db181de8f1f4ac5d18e3e2f0b6 /testsuite
parent933d61a44a9409bf0d4bff0cceca1f02f48da4dd (diff)
downloadhaskell-03ed0b95147ef6da99ac60302fea282d4df5f072.tar.gz
checkValidInst: Don't expand synonyms when splitting sigma types
Previously, the `checkValidInst` function (used when checking that an instance declaration is headed by an actual type class, not a type synonym) was using `tcSplitSigmaTy` to split apart the `forall`s and instance context. This is incorrect, however, as `tcSplitSigmaTy` expands type synonyms, which can cause instances headed by quantified constraint type synonyms to be accepted erroneously. This patch introduces `splitInstTyForValidity`, a variant of `tcSplitSigmaTy` specialized for validity checking that does _not_ expand type synonyms, and uses it in `checkValidInst`. Fixes #22570.
Diffstat (limited to 'testsuite')
-rw-r--r--testsuite/tests/typecheck/should_fail/T22570.hs15
-rw-r--r--testsuite/tests/typecheck/should_fail/T22570.stderr10
-rw-r--r--testsuite/tests/typecheck/should_fail/all.T1
3 files changed, 26 insertions, 0 deletions
diff --git a/testsuite/tests/typecheck/should_fail/T22570.hs b/testsuite/tests/typecheck/should_fail/T22570.hs
new file mode 100644
index 0000000000..25a54aa29b
--- /dev/null
+++ b/testsuite/tests/typecheck/should_fail/T22570.hs
@@ -0,0 +1,15 @@
+{-# LANGUAGE QuantifiedConstraints #-}
+module T22570 where
+
+import Data.Kind
+
+class SomeClass a
+class OtherClass
+
+type SomeClassUnit = OtherClass => SomeClass () :: Constraint
+
+instance SomeClassUnit
+
+type SomeClassSyn a = OtherClass => SomeClass a :: Constraint
+
+instance SomeClassSyn ()
diff --git a/testsuite/tests/typecheck/should_fail/T22570.stderr b/testsuite/tests/typecheck/should_fail/T22570.stderr
new file mode 100644
index 0000000000..023d1508e4
--- /dev/null
+++ b/testsuite/tests/typecheck/should_fail/T22570.stderr
@@ -0,0 +1,10 @@
+
+T22570.hs:11:10: error: [GHC-53946]
+ • Illegal instance for a type synonym
+ A class instance must be for a class
+ • In the instance declaration for ‘SomeClassUnit’
+
+T22570.hs:15:10: error: [GHC-53946]
+ • Illegal instance for a type synonym
+ A class instance must be for a class
+ • In the instance declaration for ‘SomeClassSyn ()’
diff --git a/testsuite/tests/typecheck/should_fail/all.T b/testsuite/tests/typecheck/should_fail/all.T
index 8d3af674ab..a99792e5ab 100644
--- a/testsuite/tests/typecheck/should_fail/all.T
+++ b/testsuite/tests/typecheck/should_fail/all.T
@@ -665,3 +665,4 @@ test('MissingDefaultMethodBinding', normal, compile_fail, [''])
test('T21447', normal, compile_fail, [''])
test('T21530a', normal, compile_fail, [''])
test('T21530b', normal, compile_fail, [''])
+test('T22570', normal, compile_fail, [''])