Testcase for type family consistency checks
authorBartosz Nitka <niteria@gmail.com>
Mon, 22 May 2017 16:01:05 +0000 (12:01 -0400)
committerBen Gamari <ben@smart-cactus.org>
Mon, 22 May 2017 16:41:20 +0000 (12:41 -0400)
Based on my quick search, we don't have a test
that verifies that we check the type family instances of
currently compiled module against direct or indirect
dependencies.

This adds two tests: for a direct dependency and
for an indirect dependency.

I also added a comment to make it clear what the 'Over'
test tests.

Other than completeness, it makes sense to have these
tests because if you look at
Note [The type family instance consistency story] in FamInsts
these cases are checked through different mechanisms.

Test Plan: new tests

Reviewers: simonmar, rwbarton, simonpj, austin, bgamari

Reviewed By: simonpj, bgamari

Subscribers: thomie

GHC Trac Issues: #13719

Differential Revision: https://phabricator.haskell.org/D3602

testsuite/tests/indexed-types/should_fail/OverD.hs
testsuite/tests/indexed-types/should_fail/OverDirectThisMod.stderr [new file with mode: 0644]
testsuite/tests/indexed-types/should_fail/OverDirectThisModA.hs [new file with mode: 0644]
testsuite/tests/indexed-types/should_fail/OverDirectThisModB.hs [new file with mode: 0644]
testsuite/tests/indexed-types/should_fail/OverDirectThisModC.hs [new file with mode: 0644]
testsuite/tests/indexed-types/should_fail/OverIndirectThisMod.stderr [new file with mode: 0644]
testsuite/tests/indexed-types/should_fail/OverIndirectThisModA.hs [new file with mode: 0644]
testsuite/tests/indexed-types/should_fail/OverIndirectThisModB.hs [new file with mode: 0644]
testsuite/tests/indexed-types/should_fail/OverIndirectThisModC.hs [new file with mode: 0644]
testsuite/tests/indexed-types/should_fail/OverIndirectThisModD.hs [new file with mode: 0644]
testsuite/tests/indexed-types/should_fail/all.T

index 3bce8de..ec57974 100644 (file)
@@ -1,3 +1,5 @@
 module OverD where
+-- Tests that we verify consistency of type families between
+-- transitive imports.
 import OverB
 import OverC
diff --git a/testsuite/tests/indexed-types/should_fail/OverDirectThisMod.stderr b/testsuite/tests/indexed-types/should_fail/OverDirectThisMod.stderr
new file mode 100644 (file)
index 0000000..28c72df
--- /dev/null
@@ -0,0 +1,10 @@
+
+OverDirectThisModB.hs:7:15: error:
+    Conflicting family instance declarations:
+      C [Int] [a] = CListList2 -- Defined at OverDirectThisModB.hs:7:15
+      C [a] [Int] = C9ListList -- Defined at OverDirectThisModC.hs:10:15
+
+OverDirectThisModB.hs:9:15: error:
+    Conflicting family instance declarations:
+      D [Int] [a] = Int -- Defined at OverDirectThisModB.hs:9:15
+      D [a] [Int] = Char -- Defined at OverDirectThisModC.hs:12:15
diff --git a/testsuite/tests/indexed-types/should_fail/OverDirectThisModA.hs b/testsuite/tests/indexed-types/should_fail/OverDirectThisModA.hs
new file mode 100644 (file)
index 0000000..d2655b6
--- /dev/null
@@ -0,0 +1,8 @@
+{-# LANGUAGE TypeFamilies #-}
+
+module OverDirectThisModA (C, D)
+where
+
+data family C a b :: *
+
+type family D a b :: *
diff --git a/testsuite/tests/indexed-types/should_fail/OverDirectThisModB.hs b/testsuite/tests/indexed-types/should_fail/OverDirectThisModB.hs
new file mode 100644 (file)
index 0000000..4215edf
--- /dev/null
@@ -0,0 +1,9 @@
+{-# LANGUAGE TypeFamilies #-}
+
+module OverDirectThisModB
+where
+import OverDirectThisModA (C, D)
+
+data instance C [Int] [a] = CListList2
+
+type instance D [Int] [a] = Int
diff --git a/testsuite/tests/indexed-types/should_fail/OverDirectThisModC.hs b/testsuite/tests/indexed-types/should_fail/OverDirectThisModC.hs
new file mode 100644 (file)
index 0000000..aa0f888
--- /dev/null
@@ -0,0 +1,12 @@
+{-# LANGUAGE TypeFamilies #-}
+-- Tests that we check family instance consistency between
+-- type family instances defined in the currently compiled module
+-- and the direct imports.
+module OverDirectThisModC
+where
+import OverDirectThisModB
+import OverDirectThisModA (C, D)
+
+data instance C [a] [Int] = C9ListList
+
+type instance D [a] [Int] = Char
diff --git a/testsuite/tests/indexed-types/should_fail/OverIndirectThisMod.stderr b/testsuite/tests/indexed-types/should_fail/OverIndirectThisMod.stderr
new file mode 100644 (file)
index 0000000..53c93e8
--- /dev/null
@@ -0,0 +1,12 @@
+
+OverIndirectThisModB.hs:7:15: error:
+    Conflicting family instance declarations:
+      C [Int] [a] = OverIndirectThisModB.CListList2
+        -- Defined at OverIndirectThisModB.hs:7:15
+      C [a] [Int] = C9ListList
+        -- Defined at OverIndirectThisModD.hs:11:15
+
+OverIndirectThisModB.hs:9:15: error:
+    Conflicting family instance declarations:
+      D [Int] [a] = Int -- Defined at OverIndirectThisModB.hs:9:15
+      D [a] [Int] = Char -- Defined at OverIndirectThisModD.hs:13:15
diff --git a/testsuite/tests/indexed-types/should_fail/OverIndirectThisModA.hs b/testsuite/tests/indexed-types/should_fail/OverIndirectThisModA.hs
new file mode 100644 (file)
index 0000000..f316ac1
--- /dev/null
@@ -0,0 +1,8 @@
+{-# LANGUAGE TypeFamilies #-}
+
+module OverIndirectThisModA (C, D)
+where
+
+data family C a b :: *
+
+type family D a b :: *
diff --git a/testsuite/tests/indexed-types/should_fail/OverIndirectThisModB.hs b/testsuite/tests/indexed-types/should_fail/OverIndirectThisModB.hs
new file mode 100644 (file)
index 0000000..ed152d5
--- /dev/null
@@ -0,0 +1,9 @@
+{-# LANGUAGE TypeFamilies #-}
+
+module OverIndirectThisModB
+where
+import OverIndirectThisModA (C, D)
+
+data instance C [Int] [a] = CListList2
+
+type instance D [Int] [a] = Int
diff --git a/testsuite/tests/indexed-types/should_fail/OverIndirectThisModC.hs b/testsuite/tests/indexed-types/should_fail/OverIndirectThisModC.hs
new file mode 100644 (file)
index 0000000..e39a27d
--- /dev/null
@@ -0,0 +1,2 @@
+module OverIndirectThisModC where
+import OverIndirectThisModB
diff --git a/testsuite/tests/indexed-types/should_fail/OverIndirectThisModD.hs b/testsuite/tests/indexed-types/should_fail/OverIndirectThisModD.hs
new file mode 100644 (file)
index 0000000..a75007b
--- /dev/null
@@ -0,0 +1,13 @@
+{-# LANGUAGE TypeFamilies #-}
+-- Tests that we check family instance consistency between
+-- type family instances defined in the currently compiled module
+-- and the transitive imports.
+module OverIndirectThisModD
+where
+import OverIndirectThisModC
+  -- imports OverIndirectThisModB with conflicting instances
+import OverIndirectThisModA (C, D)
+
+data instance C [a] [Int] = C9ListList
+
+type instance D [a] [Int] = Char
index cca1e8d..9cad8e1 100644 (file)
@@ -30,6 +30,8 @@ test('NonLinearSigErr', normal, compile, [''])
 test('GADTwrong1', normal, compile_fail, [''])
 
 test('Over', [], multimod_compile_fail, ['OverD', '-no-hs-main -c -v0'])
+test('OverDirectThisMod', [], multimod_compile_fail, ['OverDirectThisModC', '-no-hs-main -c -v0'])
+test('OverIndirectThisMod', [], multimod_compile_fail, ['OverIndirectThisModD', '-no-hs-main -c -v0'])
 
 test('SkolemOccursLoop', expect_fail, compile_fail, [''])