diff options
author | Ryan Scott <ryan.gl.scott@gmail.com> | 2020-11-13 10:56:20 -0500 |
---|---|---|
committer | Marge Bot <ben+marge-bot@smart-cactus.org> | 2020-11-15 03:36:21 -0500 |
commit | 645444af9eb185684c750c95e4740d301352b2b9 (patch) | |
tree | 6e2e1136560d7e2acf1075c3974a65c18ae10512 /testsuite/tests/typecheck | |
parent | d61adb3dace8f52e21f302989182145a0efa103f (diff) | |
download | haskell-645444af9eb185684c750c95e4740d301352b2b9.tar.gz |
Use tcSplitForAllInvisTyVars (not tcSplitForAllTyVars) in more places
The use of `tcSplitForAllTyVars` in `tcDataFamInstHeader` was the immediate
cause of #18939, and replacing it with a new `tcSplitForAllInvisTyVars`
function (which behaves like `tcSplitForAllTyVars` but only splits invisible
type variables) fixes the issue. However, this led me to realize that _most_
uses of `tcSplitForAllTyVars` in GHC really ought to be
`tcSplitForAllInvisTyVars` instead. While I was in town, I opted to replace
most uses of `tcSplitForAllTys` with `tcSplitForAllTysInvis` to reduce the
likelihood of such bugs in the future.
I say "most uses" above since there is one notable place where we _do_ want
to use `tcSplitForAllTyVars`: in `GHC.Tc.Validity.forAllTyErr`, which produces
the "`Illegal polymorphic type`" error message if you try to use a higher-rank
`forall` without having `RankNTypes` enabled. Here, we really do want to split
all `forall`s, not just invisible ones, or we run the risk of giving an
inaccurate error message in the newly added `T18939_Fail` test case.
I debated at some length whether I wanted to name the new function
`tcSplitForAllInvisTyVars` or `tcSplitForAllTyVarsInvisible`, but in the end,
I decided that I liked the former better. For consistency's sake, I opted to
rename the existing `splitPiTysInvisible` and `splitPiTysInvisibleN` functions
to `splitInvisPiTys` and `splitPiTysInvisN`, respectively, so that they use the
same naming convention. As a consequence, this ended up requiring a `haddock`
submodule bump.
Fixes #18939.
Diffstat (limited to 'testsuite/tests/typecheck')
5 files changed, 23 insertions, 0 deletions
diff --git a/testsuite/tests/typecheck/should_compile/T18939_Compile.hs b/testsuite/tests/typecheck/should_compile/T18939_Compile.hs new file mode 100644 index 0000000000..8c2123f111 --- /dev/null +++ b/testsuite/tests/typecheck/should_compile/T18939_Compile.hs @@ -0,0 +1,11 @@ +{-# LANGUAGE DataKinds #-} +{-# LANGUAGE PolyKinds #-} +{-# LANGUAGE RankNTypes #-} +{-# LANGUAGE StandaloneKindSignatures #-} +{-# LANGUAGE TypeFamilies #-} +module T18939_Compile where + +import Data.Kind + +data family Hm :: forall a -> a -> Type +data instance Hm :: forall a -> a -> Type diff --git a/testsuite/tests/typecheck/should_compile/all.T b/testsuite/tests/typecheck/should_compile/all.T index 263ff97ba1..4482e3fdc4 100644 --- a/testsuite/tests/typecheck/should_compile/all.T +++ b/testsuite/tests/typecheck/should_compile/all.T @@ -726,6 +726,7 @@ test('T18323', normal, compile, ['']) test('T18585', normal, compile, ['']) test('T18831', normal, compile, ['']) test('T18920', normal, compile, ['']) +test('T18939_Compile', normal, compile, ['']) test('T15942', normal, compile, ['']) test('ClassDefaultInHsBoot', [extra_files(['ClassDefaultInHsBootA1.hs','ClassDefaultInHsBootA2.hs','ClassDefaultInHsBootA2.hs-boot','ClassDefaultInHsBootA3.hs'])], multimod_compile, ['ClassDefaultInHsBoot', '-v0']) test('T17186', normal, compile, ['']) diff --git a/testsuite/tests/typecheck/should_fail/T18939_Fail.hs b/testsuite/tests/typecheck/should_fail/T18939_Fail.hs new file mode 100644 index 0000000000..c2faade865 --- /dev/null +++ b/testsuite/tests/typecheck/should_fail/T18939_Fail.hs @@ -0,0 +1,5 @@ +{-# LANGUAGE ExplicitForAll #-} +{-# LANGUAGE PolyKinds #-} +module T18939_Fail where + +data F (f :: forall a -> a) diff --git a/testsuite/tests/typecheck/should_fail/T18939_Fail.stderr b/testsuite/tests/typecheck/should_fail/T18939_Fail.stderr new file mode 100644 index 0000000000..2cdbab4bb3 --- /dev/null +++ b/testsuite/tests/typecheck/should_fail/T18939_Fail.stderr @@ -0,0 +1,5 @@ + +T18939_Fail.hs:5:1: error: + ⢠Illegal polymorphic type: forall a -> a + Perhaps you intended to use RankNTypes + ⢠In the data type declaration for âFâ diff --git a/testsuite/tests/typecheck/should_fail/all.T b/testsuite/tests/typecheck/should_fail/all.T index 1a260c5dc4..5ce09273a2 100644 --- a/testsuite/tests/typecheck/should_fail/all.T +++ b/testsuite/tests/typecheck/should_fail/all.T @@ -583,6 +583,7 @@ test('T18714', normal, compile_fail, ['']) test('T18723a', normal, compile_fail, ['']) test('T18723b', normal, compile_fail, ['']) test('T18723c', normal, compile_fail, ['']) +test('T18939_Fail', normal, compile_fail, ['']) test('too-many', normal, compile_fail, ['']) test('T18640a', normal, compile_fail, ['']) test('T18640b', normal, compile_fail, ['']) |