summaryrefslogtreecommitdiff
path: root/testsuite
diff options
context:
space:
mode:
authorSimon Peyton Jones <simonpj@microsoft.com>2020-01-23 09:40:33 +0000
committerMarge Bot <ben+marge-bot@smart-cactus.org>2020-02-01 02:28:45 -0500
commit913287a0fa5370a2488ce560f2dfba61db51055d (patch)
tree6506f059b45bd05b29b45095c3a3cbdb49f2f609 /testsuite
parentcd11042337a829da1dfbd19ca1a46feabdd23147 (diff)
downloadhaskell-913287a0fa5370a2488ce560f2dfba61db51055d.tar.gz
Fix scoping of TyCon binders in TcTyClsDecls
This patch fixes #17566 by refactoring the way we decide the final identity of the tyvars in the TyCons of a possibly-recursive nest of type and class decls, possibly with associated types. It's all laid out in Note [Swizzling the tyvars before generaliseTcTyCon] Main changes: * We have to generalise each decl (with its associated types) all at once: TcTyClsDecls.generaliseTyClDecl * The main new work is done in TcTyClsDecls.swizzleTcTyConBndrs * The mysterious TcHsSyn.zonkRecTyVarBndrs dies altogether Other smaller things: * A little refactoring, moving bindTyClTyVars from tcTyClDecl1 to tcDataDefn, tcSynRhs, etc. Clearer, reduces the number of parameters * Reduce the amount of swizzling required. Specifically, bindExplicitTKBndrs_Q_Tv doesn't need to clone a new Name for the TyVarTv, and not cloning means that in the vasly common case, swizzleTyConBndrs is a no-op In detail: Rename newTyVarTyVar --> cloneTyVarTyVar Add newTyVarTyTyVar that doesn't clone Use the non-cloning newTyVarTyVar in bindExplicitTKBndrs_Q_Tv Rename newFlexiKindedTyVarTyVar --> cloneFlexiKindedTyVarTyVar * Define new utility function and use it HsDecls.familyDeclName :: FamilyDecl (GhcPass p) -> IdP (GhcPass p) Updates haddock submodule.
Diffstat (limited to 'testsuite')
-rw-r--r--testsuite/tests/polykinds/T11203.stderr4
-rw-r--r--testsuite/tests/polykinds/T11821a.stderr4
-rw-r--r--testsuite/tests/typecheck/should_compile/Makefile5
-rw-r--r--testsuite/tests/typecheck/should_compile/T17566.hs20
-rw-r--r--testsuite/tests/typecheck/should_compile/T17566a.hs15
-rw-r--r--testsuite/tests/typecheck/should_compile/all.T1
-rw-r--r--testsuite/tests/typecheck/should_fail/T17566b.hs7
-rw-r--r--testsuite/tests/typecheck/should_fail/T17566b.stderr4
-rw-r--r--testsuite/tests/typecheck/should_fail/T17566c.hs11
-rw-r--r--testsuite/tests/typecheck/should_fail/T17566c.stderr6
-rw-r--r--testsuite/tests/typecheck/should_fail/all.T2
11 files changed, 75 insertions, 4 deletions
diff --git a/testsuite/tests/polykinds/T11203.stderr b/testsuite/tests/polykinds/T11203.stderr
index f5c72133ae..e6f30c0335 100644
--- a/testsuite/tests/polykinds/T11203.stderr
+++ b/testsuite/tests/polykinds/T11203.stderr
@@ -1,4 +1,4 @@
T11203.hs:7:24: error:
- • Couldn't match ‘k1’ with ‘k2’
- • In the data type declaration for ‘Q’
+ • Different names for the same type variable: ‘k1’ and ‘k2’
+ • In the data declaration for ‘Q’
diff --git a/testsuite/tests/polykinds/T11821a.stderr b/testsuite/tests/polykinds/T11821a.stderr
index f55c703524..50d58df8f5 100644
--- a/testsuite/tests/polykinds/T11821a.stderr
+++ b/testsuite/tests/polykinds/T11821a.stderr
@@ -1,4 +1,4 @@
T11821a.hs:4:31: error:
- • Couldn't match ‘k1’ with ‘k2’
- • In the type synonym declaration for ‘SameKind’
+ • Different names for the same type variable: ‘k1’ and ‘k2’
+ • In the type declaration for ‘SameKind’
diff --git a/testsuite/tests/typecheck/should_compile/Makefile b/testsuite/tests/typecheck/should_compile/Makefile
index 5255485601..5c0c84f8ec 100644
--- a/testsuite/tests/typecheck/should_compile/Makefile
+++ b/testsuite/tests/typecheck/should_compile/Makefile
@@ -75,3 +75,8 @@ T14934:
$(RM) -f T14934a.o T14934a.hi T14934.o T14934.hi
'$(TEST_HC)' $(TEST_HC_OPTS) -c T14934a.hs -O
'$(TEST_HC)' $(TEST_HC_OPTS) -c T14934.hs -O
+
+T17566:
+ $(RM) -f T17566a.o T17566a.hi T17566.o T17566.hi
+ '$(TEST_HC)' $(TEST_HC_OPTS) -c T17566a.hs
+ '$(TEST_HC)' $(TEST_HC_OPTS) -c T17566.hs
diff --git a/testsuite/tests/typecheck/should_compile/T17566.hs b/testsuite/tests/typecheck/should_compile/T17566.hs
new file mode 100644
index 0000000000..5996bd7d47
--- /dev/null
+++ b/testsuite/tests/typecheck/should_compile/T17566.hs
@@ -0,0 +1,20 @@
+{-# LANGUAGE DataKinds #-}
+{-# LANGUAGE FlexibleInstances #-}
+{-# LANGUAGE MultiParamTypeClasses #-}
+{-# LANGUAGE PolyKinds #-}
+{-# LANGUAGE TypeFamilies #-}
+module T17566 where
+
+import Data.Kind
+import Data.Proxy
+import T17566a
+
+type family F1 (x :: Proxy a) :: Proxy a
+instance C1 Proxy z where
+ type T1 x = F1 x
+ data D1 x
+
+type family F2 (x :: Proxy a) :: Proxy a
+instance C2 Proxy z where
+ type T2 x = F2 x
+ data D2 x
diff --git a/testsuite/tests/typecheck/should_compile/T17566a.hs b/testsuite/tests/typecheck/should_compile/T17566a.hs
new file mode 100644
index 0000000000..6255a7a7ba
--- /dev/null
+++ b/testsuite/tests/typecheck/should_compile/T17566a.hs
@@ -0,0 +1,15 @@
+{-# LANGUAGE DataKinds #-}
+{-# LANGUAGE MultiParamTypeClasses #-}
+{-# LANGUAGE PolyKinds #-}
+{-# LANGUAGE TypeFamilies #-}
+module T17566a where
+
+import Data.Kind
+
+class C1 (f :: k -> Type) z where
+ type T1 (x :: f a) :: f a
+ data D1 (x :: f a)
+
+class C2 f z where
+ type T2 (x :: f a) :: f a
+ data D2 (x :: f a)
diff --git a/testsuite/tests/typecheck/should_compile/all.T b/testsuite/tests/typecheck/should_compile/all.T
index 80b11ca851..0f61b57faf 100644
--- a/testsuite/tests/typecheck/should_compile/all.T
+++ b/testsuite/tests/typecheck/should_compile/all.T
@@ -692,3 +692,4 @@ test('T17202', expect_broken(17202), compile, [''])
test('T15839a', normal, compile, [''])
test('T15839b', normal, compile, [''])
test('T17343', exit_code(1), compile_and_run, [''])
+test('T17566', [extra_files(['T17566a.hs'])], makefile_test, [])
diff --git a/testsuite/tests/typecheck/should_fail/T17566b.hs b/testsuite/tests/typecheck/should_fail/T17566b.hs
new file mode 100644
index 0000000000..7b1711ada6
--- /dev/null
+++ b/testsuite/tests/typecheck/should_fail/T17566b.hs
@@ -0,0 +1,7 @@
+{-# LANGUAGE PolyKinds #-}
+{-# LANGUAGE TypeFamilies #-}
+module T17566b where
+
+class C f where
+ type T1 (f :: k1)
+ type T2 (f :: k2)
diff --git a/testsuite/tests/typecheck/should_fail/T17566b.stderr b/testsuite/tests/typecheck/should_fail/T17566b.stderr
new file mode 100644
index 0000000000..be3c0e19bd
--- /dev/null
+++ b/testsuite/tests/typecheck/should_fail/T17566b.stderr
@@ -0,0 +1,4 @@
+
+T17566b.hs:7:17: error:
+ • Different names for the same type variable: ‘k1’ and ‘k2’
+ • In the class declaration for ‘C’
diff --git a/testsuite/tests/typecheck/should_fail/T17566c.hs b/testsuite/tests/typecheck/should_fail/T17566c.hs
new file mode 100644
index 0000000000..d7d68a050c
--- /dev/null
+++ b/testsuite/tests/typecheck/should_fail/T17566c.hs
@@ -0,0 +1,11 @@
+{-# LANGUAGE DataKinds #-}
+{-# LANGUAGE MultiParamTypeClasses #-}
+{-# LANGUAGE PolyKinds #-}
+{-# LANGUAGE TypeFamilies #-}
+module T17566c where
+
+import Data.Kind
+
+class C2 f z where
+ type T2 (f :: k -> Type)
+ data D2 (x :: (f :: k -> Type) a)
diff --git a/testsuite/tests/typecheck/should_fail/T17566c.stderr b/testsuite/tests/typecheck/should_fail/T17566c.stderr
new file mode 100644
index 0000000000..df5e5c0739
--- /dev/null
+++ b/testsuite/tests/typecheck/should_fail/T17566c.stderr
@@ -0,0 +1,6 @@
+
+T17566c.hs:11:23: error:
+ • Different names for the same type variable:
+ ‘k’ bound at T17566c.hs:10:17
+ ‘k’ bound at T17566c.hs:11:23
+ • In the class declaration for ‘C2’
diff --git a/testsuite/tests/typecheck/should_fail/all.T b/testsuite/tests/typecheck/should_fail/all.T
index e11c239742..f0f290c405 100644
--- a/testsuite/tests/typecheck/should_fail/all.T
+++ b/testsuite/tests/typecheck/should_fail/all.T
@@ -550,3 +550,5 @@ test('T17355', normal, compile_fail, [''])
test('T17360', normal, compile_fail, [''])
test('T17563', normal, compile_fail, [''])
test('T16946', normal, compile_fail, [''])
+test('T17566b', normal, compile_fail, [''])
+test('T17566c', normal, compile_fail, [''])