diff options
author | Ryan Scott <ryan.gl.scott@gmail.com> | 2018-10-15 13:48:21 -0400 |
---|---|---|
committer | Ben Gamari <ben@smart-cactus.org> | 2018-10-15 17:59:20 -0400 |
commit | 26e81e90281685af37c8f2cf149c242b4039117a (patch) | |
tree | 7a3af42bd72026255434f5e0322fb3938f19e51a | |
parent | 0b0cb484eb0b51bf5485dfadff7cd8a079ceb16e (diff) | |
download | haskell-26e81e90281685af37c8f2cf149c242b4039117a.tar.gz |
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
-rw-r--r-- | compiler/typecheck/FamInst.hs | 3 | ||||
-rw-r--r-- | testsuite/tests/typecheck/should_fail/T12430.hs | 6 | ||||
-rw-r--r-- | testsuite/tests/typecheck/should_fail/T12430.stderr | 8 | ||||
-rw-r--r-- | testsuite/tests/typecheck/should_fail/all.T | 1 |
4 files changed, 18 insertions, 0 deletions
diff --git a/compiler/typecheck/FamInst.hs b/compiler/typecheck/FamInst.hs index dc6eab8081..8f1f7ba5f6 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 0000000000..03cded2b44 --- /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 0000000000..c3d9446197 --- /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 274dcc669e..501c5e1651 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, ['']) |