diff options
author | Ryan Scott <ryan.gl.scott@gmail.com> | 2020-07-16 14:04:28 -0400 |
---|---|---|
committer | Marge Bot <ben+marge-bot@smart-cactus.org> | 2020-07-30 07:11:37 -0400 |
commit | 01c948eba4bea2d2c8ad340e12c1e7b732b334f7 (patch) | |
tree | 24d79117dd80af9d4c9b9d7f4c23c39bf335b260 /testsuite/tests/typecheck | |
parent | 502de55676a38572db60848c13392f5f115e1c8a (diff) | |
download | haskell-01c948eba4bea2d2c8ad340e12c1e7b732b334f7.tar.gz |
Clean up the inferred type variable restriction
This patch primarily:
* Documents `checkInferredVars` (previously called
`check_inferred_vars`) more carefully. This is the
function which throws an error message if a user quantifies an
inferred type variable in a place where specificity cannot be
observed. See `Note [Unobservably inferred type variables]` in
`GHC.Rename.HsType`.
Note that I now invoke `checkInferredVars` _alongside_
`rnHsSigType`, `rnHsWcSigType`, etc. rather than doing so _inside_
of these functions. This results in slightly more call sites for
`checkInferredVars`, but it makes it much easier to enumerate the
spots where the inferred type variable restriction comes into
effect.
* Removes the inferred type variable restriction for default method
type signatures, per the discussion in #18432. As a result, this
patch fixes #18432.
Along the way, I performed some various cleanup:
* I moved `no_nested_foralls_contexts_err` into `GHC.Rename.Utils`
(under the new name `noNestedForallsContextsErr`), since it now
needs to be invoked from multiple modules. I also added a helper
function `addNoNestedForallsContextsErr` that throws the error
message after producing it, as this is a common idiom.
* In order to ensure that users cannot sneak inferred type variables
into `SPECIALISE instance` pragmas by way of nested `forall`s, I
now invoke `addNoNestedForallsContextsErr` when renaming
`SPECIALISE instance` pragmas, much like when we rename normal
instance declarations. (This probably should have originally been
done as a part of the fix for #18240, but this task was somehow
overlooked.) As a result, this patch fixes #18455 as a side effect.
Diffstat (limited to 'testsuite/tests/typecheck')
-rw-r--r-- | testsuite/tests/typecheck/should_compile/ExplicitSpecificity4.hs (renamed from testsuite/tests/typecheck/should_fail/ExplicitSpecificity4.hs) | 0 | ||||
-rw-r--r-- | testsuite/tests/typecheck/should_compile/all.T | 1 | ||||
-rw-r--r-- | testsuite/tests/typecheck/should_fail/T18455.hs | 7 | ||||
-rw-r--r-- | testsuite/tests/typecheck/should_fail/T18455.stderr | 4 | ||||
-rw-r--r-- | testsuite/tests/typecheck/should_fail/all.T | 2 |
5 files changed, 13 insertions, 1 deletions
diff --git a/testsuite/tests/typecheck/should_fail/ExplicitSpecificity4.hs b/testsuite/tests/typecheck/should_compile/ExplicitSpecificity4.hs index 4d615631b6..4d615631b6 100644 --- a/testsuite/tests/typecheck/should_fail/ExplicitSpecificity4.hs +++ b/testsuite/tests/typecheck/should_compile/ExplicitSpecificity4.hs diff --git a/testsuite/tests/typecheck/should_compile/all.T b/testsuite/tests/typecheck/should_compile/all.T index 82a30f50f4..5917318476 100644 --- a/testsuite/tests/typecheck/should_compile/all.T +++ b/testsuite/tests/typecheck/should_compile/all.T @@ -712,6 +712,7 @@ test('T18129', expect_broken(18129), compile, ['']) test('T18185', normal, compile, ['']) test('ExplicitSpecificityA1', normal, compile, ['']) test('ExplicitSpecificityA2', normal, compile, ['']) +test('ExplicitSpecificity4', normal, compile, ['']) test('T17775-viewpats-a', normal, compile, ['']) test('T17775-viewpats-b', normal, compile_fail, ['']) test('T17775-viewpats-c', normal, compile_fail, ['']) diff --git a/testsuite/tests/typecheck/should_fail/T18455.hs b/testsuite/tests/typecheck/should_fail/T18455.hs new file mode 100644 index 0000000000..ad151ae9a7 --- /dev/null +++ b/testsuite/tests/typecheck/should_fail/T18455.hs @@ -0,0 +1,7 @@ +{-# LANGUAGE RankNTypes #-} +module T18455 where + +class C a + +instance C (Either a b) where + {-# SPECIALISE instance forall a. forall b. C (Either a b) #-} diff --git a/testsuite/tests/typecheck/should_fail/T18455.stderr b/testsuite/tests/typecheck/should_fail/T18455.stderr new file mode 100644 index 0000000000..15d02d1902 --- /dev/null +++ b/testsuite/tests/typecheck/should_fail/T18455.stderr @@ -0,0 +1,4 @@ + +T18455.hs:7:37: error: + SPECIALISE instance type cannot contain nested ‘forall’s or contexts + In a SPECIALISE instance pragma diff --git a/testsuite/tests/typecheck/should_fail/all.T b/testsuite/tests/typecheck/should_fail/all.T index c9b785554e..7b4d6d1899 100644 --- a/testsuite/tests/typecheck/should_fail/all.T +++ b/testsuite/tests/typecheck/should_fail/all.T @@ -568,7 +568,6 @@ test('T18127a', normal, compile_fail, ['']) test('ExplicitSpecificity1', normal, compile_fail, ['']) test('ExplicitSpecificity2', normal, compile_fail, ['']) test('ExplicitSpecificity3', normal, compile_fail, ['']) -test('ExplicitSpecificity4', normal, compile_fail, ['']) test('ExplicitSpecificity5', normal, compile_fail, ['']) test('ExplicitSpecificity6', normal, compile_fail, ['']) test('ExplicitSpecificity7', normal, compile_fail, ['']) @@ -578,3 +577,4 @@ test('ExplicitSpecificity10', normal, compile_fail, ['']) test('T18357', normal, compile_fail, ['']) test('T18357a', normal, compile_fail, ['']) test('T18357b', normal, compile_fail, ['']) +test('T18455', normal, compile_fail, ['']) |