[commit: ghc] master: Fix #12430 by expanding type synonyms in injTyVarsOfType (26e81e9)

git at git.haskell.org git at git.haskell.org
Mon Oct 15 22:34:47 UTC 2018


Repository : ssh://git@git.haskell.org/ghc

On branch  : master
Link       : http://ghc.haskell.org/trac/ghc/changeset/26e81e90281685af37c8f2cf149c242b4039117a/ghc

>---------------------------------------------------------------

commit 26e81e90281685af37c8f2cf149c242b4039117a
Author: Ryan Scott <ryan.gl.scott at gmail.com>
Date:   Mon Oct 15 13:48:21 2018 -0400

    Fix #12430 by expanding type synonyms in injTyVarsOfType
    
    We weren't expanding type synonyms when determining the
    injective type variables of a type, leading to certain non-injective
    families being mistakenly labeled as injective (#12430). Easily fixed
    with a tactical use of `coreView`.
    
    Test Plan: make test TEST=T12430
    
    Reviewers: bgamari, goldfire
    
    Reviewed By: goldfire
    
    Subscribers: goldfire, rwbarton, carter
    
    GHC Trac Issues: #12430
    
    Differential Revision: https://phabricator.haskell.org/D5228


>---------------------------------------------------------------

26e81e90281685af37c8f2cf149c242b4039117a
 compiler/typecheck/FamInst.hs                       | 3 +++
 testsuite/tests/typecheck/should_fail/T12430.hs     | 6 ++++++
 testsuite/tests/typecheck/should_fail/T12430.stderr | 8 ++++++++
 testsuite/tests/typecheck/should_fail/all.T         | 1 +
 4 files changed, 18 insertions(+)

diff --git a/compiler/typecheck/FamInst.hs b/compiler/typecheck/FamInst.hs
index dc6eab8..8f1f7ba 100644
--- a/compiler/typecheck/FamInst.hs
+++ b/compiler/typecheck/FamInst.hs
@@ -792,6 +792,9 @@ injTyVarsOfType :: TcTauType -> TcTyVarSet
 -- E.g.   Suppose F is injective in its second arg, but not its first
 --        then injVarOfType (Either a (F [b] (a,c))) = {a,c}
 --        Determining the overall type determines a,c but not b.
+injTyVarsOfType ty
+  | Just ty' <- coreView ty -- #12430
+  = injTyVarsOfType ty'
 injTyVarsOfType (TyVarTy v)
   = unitVarSet v `unionVarSet` injTyVarsOfType (tyVarKind v)
 injTyVarsOfType (TyConApp tc tys)
diff --git a/testsuite/tests/typecheck/should_fail/T12430.hs b/testsuite/tests/typecheck/should_fail/T12430.hs
new file mode 100644
index 0000000..03cded2
--- /dev/null
+++ b/testsuite/tests/typecheck/should_fail/T12430.hs
@@ -0,0 +1,6 @@
+{-# LANGUAGE TypeFamilyDependencies #-}
+module T12430 where
+
+type C a = Int
+type family F x = y | y -> x where
+  F x = C x
diff --git a/testsuite/tests/typecheck/should_fail/T12430.stderr b/testsuite/tests/typecheck/should_fail/T12430.stderr
new file mode 100644
index 0000000..c3d9446
--- /dev/null
+++ b/testsuite/tests/typecheck/should_fail/T12430.stderr
@@ -0,0 +1,8 @@
+
+T12430.hs:6:3: error:
+    • Type family equation violates injectivity annotation.
+      Type variable ‘x’ cannot be inferred from the right-hand side.
+      In the type family equation:
+        F x = C x -- Defined at T12430.hs:6:3
+    • In the equations for closed type family ‘F’
+      In the type family declaration for ‘F’
diff --git a/testsuite/tests/typecheck/should_fail/all.T b/testsuite/tests/typecheck/should_fail/all.T
index 274dcc6..501c5e1 100644
--- a/testsuite/tests/typecheck/should_fail/all.T
+++ b/testsuite/tests/typecheck/should_fail/all.T
@@ -413,6 +413,7 @@ test('T12177', normal, compile_fail, [''])
 test('T12406', normal, compile_fail, [''])
 test('T12170a', normal, compile_fail, [''])
 test('T12124', normal, compile_fail, [''])
+test('T12430', normal, compile_fail, [''])
 test('T12589', normal, compile_fail, [''])
 test('T12529', normal, compile_fail, [''])
 test('T12563', normal, compile_fail, [''])



More information about the ghc-commits mailing list