Fix #14390 by making toIfaceTyCon aware of equality
authorRyan Scott <ryan.gl.scott@gmail.com>
Mon, 30 Oct 2017 00:48:19 +0000 (20:48 -0400)
committerBen Gamari <ben@smart-cactus.org>
Mon, 30 Oct 2017 01:51:05 +0000 (21:51 -0400)
GHC was panicking when pretty-printing a heterogeneous
equality type constructor (#14390) because the function which
produced the type constructor, `toIfaceTyCon`, wasn't attaching the
appropriate `IfaceTyConSort` for equality type constructors, which
is `IfaceEqualityTyCon`. This is fixed easily enough.

Test Plan: make test TEST=T14390

Reviewers: austin, bgamari

Reviewed By: bgamari

Subscribers: rwbarton, thomie

GHC Trac Issues: #14390

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

compiler/iface/ToIface.hs
testsuite/tests/typecheck/should_fail/T14390.hs [new file with mode: 0644]
testsuite/tests/typecheck/should_fail/T14390.stderr [new file with mode: 0644]
testsuite/tests/typecheck/should_fail/all.T

index 9eceb6d..6f71af5 100644 (file)
@@ -195,6 +195,12 @@ toIfaceTyCon tc
       | isUnboxedSumTyCon tc
       , Just cons <- isDataSumTyCon_maybe tc = IfaceSumTyCon (length cons)
 
+      | tyConName tc == eqTyConName || tc == eqPrimTyCon
+      = IfaceEqualityTyCon True
+
+      | tc `elem` [heqTyCon, eqReprPrimTyCon]
+      = IfaceEqualityTyCon False
+
       | otherwise                            = IfaceNormalTyCon
 
 
diff --git a/testsuite/tests/typecheck/should_fail/T14390.hs b/testsuite/tests/typecheck/should_fail/T14390.hs
new file mode 100644 (file)
index 0000000..5360be7
--- /dev/null
@@ -0,0 +1,4 @@
+module T14390 where
+
+import Data.Type.Equality
+instance (~~) Int Int
diff --git a/testsuite/tests/typecheck/should_fail/T14390.stderr b/testsuite/tests/typecheck/should_fail/T14390.stderr
new file mode 100644 (file)
index 0000000..f94bf40
--- /dev/null
@@ -0,0 +1,5 @@
+
+T14390.hs:4:10: error:
+    • Illegal instance declaration for ‘(Int :: *) ~~ (Int :: *)’
+        Manual instances of this class are not permitted.
+    • In the instance declaration for ‘(~~) Int Int’
index 1aa23c4..ca0264b 100644 (file)
@@ -460,3 +460,4 @@ test('T13929', normal, compile_fail, [''])
 test('T14232', normal, compile_fail, [''])
 test('T14325', normal, compile_fail, [''])
 test('T14350', normal, compile_fail, [''])
+test('T14390', normal, compile_fail, [''])