diff options
author | Richard Eisenberg <eir@cis.upenn.edu> | 2015-09-20 17:39:17 -0400 |
---|---|---|
committer | Richard Eisenberg <eir@cis.upenn.edu> | 2015-09-21 10:53:38 -0400 |
commit | 2f9809efdbc11fee445dbe3d5c555433ec3c5e6a (patch) | |
tree | 06d6702da1922186bf362653481e1112e457d42a /testsuite | |
parent | cbcad859acb350a33dec077d50438f929afbf0ad (diff) | |
download | haskell-2f9809efdbc11fee445dbe3d5c555433ec3c5e6a.tar.gz |
Slightly better `Coercible` errors.
This makes two real changes:
- Equalities like (a ~R [a]) really *are* insoluble. Previously,
GHC refused to give up when an occurs check bit on a representational
equality. But for datatypes, it really should bail.
- Now, GHC will sometimes report an occurs check error (in cases above)
for representational equalities. Previously, it never did.
This "fixes" #10715, where by "fix", I mean clarifies the error message.
It's unclear how to do more to fix that ticket.
Test cases: typecheck/should_fail/T10715{,b}
Diffstat (limited to 'testsuite')
-rw-r--r-- | testsuite/tests/typecheck/should_fail/T10715.hs | 10 | ||||
-rw-r--r-- | testsuite/tests/typecheck/should_fail/T10715.stderr | 15 | ||||
-rw-r--r-- | testsuite/tests/typecheck/should_fail/T10715b.hs | 7 | ||||
-rw-r--r-- | testsuite/tests/typecheck/should_fail/T10715b.stderr | 8 | ||||
-rw-r--r-- | testsuite/tests/typecheck/should_fail/all.T | 2 |
5 files changed, 42 insertions, 0 deletions
diff --git a/testsuite/tests/typecheck/should_fail/T10715.hs b/testsuite/tests/typecheck/should_fail/T10715.hs new file mode 100644 index 0000000000..969abd5cf2 --- /dev/null +++ b/testsuite/tests/typecheck/should_fail/T10715.hs @@ -0,0 +1,10 @@ +{-# LANGUAGE FlexibleContexts #-} +module T10715 where + +import Data.Coerce (coerce, Coercible) +import Data.Ord ( Down ) -- convenient newtype + +data X a + +doCoerce :: Coercible a (X a) => a -> X a +doCoerce = coerce diff --git a/testsuite/tests/typecheck/should_fail/T10715.stderr b/testsuite/tests/typecheck/should_fail/T10715.stderr new file mode 100644 index 0000000000..e6f85a5256 --- /dev/null +++ b/testsuite/tests/typecheck/should_fail/T10715.stderr @@ -0,0 +1,15 @@ + +T10715.hs:9:13: error: + Couldn't match representation of type ‘a’ with that of ‘X a’ + ‘a’ is a rigid type variable bound by + the type signature for: + doCoerce :: Coercible a (X a) => a -> X a + at T10715.hs:9:13 + Inaccessible code in + the type signature for: + doCoerce :: Coercible a (X a) => a -> X a + In the ambiguity check for the type signature for ‘doCoerce’: + doCoerce :: forall a. Coercible a (X a) => a -> X a + To defer the ambiguity check to use sites, enable AllowAmbiguousTypes + In the type signature for ‘doCoerce’: + doCoerce :: Coercible a (X a) => a -> X a diff --git a/testsuite/tests/typecheck/should_fail/T10715b.hs b/testsuite/tests/typecheck/should_fail/T10715b.hs new file mode 100644 index 0000000000..b2418b9b62 --- /dev/null +++ b/testsuite/tests/typecheck/should_fail/T10715b.hs @@ -0,0 +1,7 @@ +module T10715b where + +-- test error message: should complain about an occurs check + +import Data.Coerce + +foo = coerce `asTypeOf` head diff --git a/testsuite/tests/typecheck/should_fail/T10715b.stderr b/testsuite/tests/typecheck/should_fail/T10715b.stderr new file mode 100644 index 0000000000..47c85bb145 --- /dev/null +++ b/testsuite/tests/typecheck/should_fail/T10715b.stderr @@ -0,0 +1,8 @@ + +T10715b.hs:7:7: error: + Occurs check: cannot construct the infinite type: b ~ [b] + arising from a use of ‘coerce’ + Relevant bindings include foo :: [b] -> b (bound at T10715b.hs:7:1) + In the first argument of ‘asTypeOf’, namely ‘coerce’ + In the expression: coerce `asTypeOf` head + In an equation for ‘foo’: foo = coerce `asTypeOf` head diff --git a/testsuite/tests/typecheck/should_fail/all.T b/testsuite/tests/typecheck/should_fail/all.T index 0a0281a587..a005bc5f29 100644 --- a/testsuite/tests/typecheck/should_fail/all.T +++ b/testsuite/tests/typecheck/should_fail/all.T @@ -386,3 +386,5 @@ test('ExpandSynsFail3', normal, compile_fail, ['-fprint-expanded-synonyms']) test('ExpandSynsFail4', normal, compile_fail, ['-fprint-expanded-synonyms']) test('T10698', expect_broken(10698), compile_fail, ['']) test('T10836', normal, compile_fail, ['']) +test('T10715', normal, compile_fail, ['']) +test('T10715b', normal, compile_fail, ['']) |