diff options
author | Simon Peyton Jones <simonpj@microsoft.com> | 2018-06-15 09:46:30 +0100 |
---|---|---|
committer | Simon Peyton Jones <simonpj@microsoft.com> | 2018-06-15 09:47:41 +0100 |
commit | 2f6069ccf21d7be0e09016896238f417d2492ffa (patch) | |
tree | 937dde091434ea52e47d279483eab6b77bda4099 /testsuite/tests/dependent | |
parent | f903e5510d4562fddef1d4140971e2b93a45e45e (diff) | |
download | haskell-2f6069ccf21d7be0e09016896238f417d2492ffa.tar.gz |
Make better "fake tycons" in error recovery
Consider (Trac #15215)
data T a = MkT ...
data S a = ...T...MkT....
If there is an error in the definition of 'T' we add a
"fake type constructor" to the type environment, so that we
can continue to typecheck 'S'. But we /were not/ adding
a fake anything for 'MkT' and so there was an internal
error when we met 'MkT' in the body of 'S'.
The fix is to add fake tycons for all the 'implicits' of 'T'.
This is done by mk_fake_tc in TcTyClsDecls.checkValidTyCl,
which now returns a /list/ of TyCons rather than just one.
On the way I did some refactoring:
* Rename TcTyDecls.tcAddImplicits to tcAddTyConsToGblEnv
and make it /include/ the TyCons themeselves as well
as their implicits
* Some incidental refactoring about tcRecSelBinds. The main
thing is that I've avoided creating a HsValBinds that we
immediately decompose. That meant moving some deck chairs
around.
NB: The new error message for the regression test T15215
has the opaque error "Illegal constraint in a type:", flagged
in Trac #14845. But that's the fault of the latter ticket.
The fix here not to blame.
Diffstat (limited to 'testsuite/tests/dependent')
-rw-r--r-- | testsuite/tests/dependent/should_fail/T15215.hs | 12 | ||||
-rw-r--r-- | testsuite/tests/dependent/should_fail/T15215.stderr | 12 | ||||
-rw-r--r-- | testsuite/tests/dependent/should_fail/all.T | 1 |
3 files changed, 25 insertions, 0 deletions
diff --git a/testsuite/tests/dependent/should_fail/T15215.hs b/testsuite/tests/dependent/should_fail/T15215.hs new file mode 100644 index 0000000000..96fe04385b --- /dev/null +++ b/testsuite/tests/dependent/should_fail/T15215.hs @@ -0,0 +1,12 @@ +{-# LANGUAGE GADTs #-} +{-# LANGUAGE ScopedTypeVariables #-} +{-# LANGUAGE TypeInType #-} +module T15215 where + +import Data.Kind + +data A :: Type -> Type where + MkA :: Show (Maybe a) => A a + +data SA :: forall a. A a -> Type where + SMkA :: SA MkA diff --git a/testsuite/tests/dependent/should_fail/T15215.stderr b/testsuite/tests/dependent/should_fail/T15215.stderr new file mode 100644 index 0000000000..80181b44bd --- /dev/null +++ b/testsuite/tests/dependent/should_fail/T15215.stderr @@ -0,0 +1,12 @@ + +T15215.hs:9:3: error: + • Non type-variable argument in the constraint: Show (Maybe a) + (Use FlexibleContexts to permit this) + • In the definition of data constructor ‘MkA’ + In the data type declaration for ‘A’ + +T15215.hs:12:14: error: + • Illegal constraint in a type: Show (Maybe a0) + • In the first argument of ‘SA’, namely ‘MkA’ + In the type ‘SA MkA’ + In the definition of data constructor ‘SMkA’ diff --git a/testsuite/tests/dependent/should_fail/all.T b/testsuite/tests/dependent/should_fail/all.T index 5ae037dc54..8e5185f1ae 100644 --- a/testsuite/tests/dependent/should_fail/all.T +++ b/testsuite/tests/dependent/should_fail/all.T @@ -28,3 +28,4 @@ test('T14066g', normal, compile_fail, ['']) test('T14066h', normal, compile_fail, ['']) test('InferDependency', normal, compile_fail, ['']) test('T15245', normal, compile_fail, ['']) +test('T15215', normal, compile_fail, ['']) |