diff options
author | Simon Peyton Jones <simonpj@microsoft.com> | 2014-09-26 10:53:32 +0100 |
---|---|---|
committer | Simon Peyton Jones <simonpj@microsoft.com> | 2014-09-26 12:34:51 +0100 |
commit | 1a88f9a4fb373ce52284996212fc23b06848b1c0 (patch) | |
tree | f47edfba08918411312ea1825d5392d3cde43caf /testsuite | |
parent | 8c9d0ce490506fdc60d9f25d4b80774180cf92ce (diff) | |
download | haskell-1a88f9a4fb373ce52284996212fc23b06848b1c0.tar.gz |
Improve error messages from functional dependencies
Reponding to Trac #9612:
* Track the CtOrigin of a Derived equality, arising from a
functional dependency
* And report it clearly in the error stream
This relies on a previous commit, in which I stop dropping Derived
insolubles on the floor.
Diffstat (limited to 'testsuite')
-rw-r--r-- | testsuite/tests/typecheck/should_compile/FD3.stderr | 19 | ||||
-rw-r--r-- | testsuite/tests/typecheck/should_fail/FDsFromGivens.stderr | 22 | ||||
-rw-r--r-- | testsuite/tests/typecheck/should_fail/T5236.stderr | 15 | ||||
-rw-r--r-- | testsuite/tests/typecheck/should_fail/T5978.stderr | 13 | ||||
-rw-r--r-- | testsuite/tests/typecheck/should_fail/T9612.hs | 20 | ||||
-rw-r--r-- | testsuite/tests/typecheck/should_fail/T9612.stderr | 20 | ||||
-rw-r--r-- | testsuite/tests/typecheck/should_fail/all.T | 1 | ||||
-rw-r--r-- | testsuite/tests/typecheck/should_fail/tcfail143.stderr | 13 |
8 files changed, 93 insertions, 30 deletions
diff --git a/testsuite/tests/typecheck/should_compile/FD3.stderr b/testsuite/tests/typecheck/should_compile/FD3.stderr index d2364921f6..0ba6587273 100644 --- a/testsuite/tests/typecheck/should_compile/FD3.stderr +++ b/testsuite/tests/typecheck/should_compile/FD3.stderr @@ -1,5 +1,14 @@ -
-FD3.hs:15:15:
- No instance for (MkA (String, a) a) arising from a use of ‘mkA’
- In the expression: mkA a
- In an equation for ‘translate’: translate a = mkA a
+ +FD3.hs:15:15: + Couldn't match type ‘a’ with ‘(String, a)’ + ‘a’ is a rigid type variable bound by + the type signature for translate :: (String, a) -> A a + at FD3.hs:14:14 + arising from a functional dependency between: + constraint ‘MkA (String, a) a’ arising from a use of ‘mkA’ + instance ‘MkA a1 a1’ at FD3.hs:12:10-16 + Relevant bindings include + a :: (String, a) (bound at FD3.hs:15:11) + translate :: (String, a) -> A a (bound at FD3.hs:15:1) + In the expression: mkA a + In an equation for ‘translate’: translate a = mkA a diff --git a/testsuite/tests/typecheck/should_fail/FDsFromGivens.stderr b/testsuite/tests/typecheck/should_fail/FDsFromGivens.stderr index 56d3006260..f3320d0d8e 100644 --- a/testsuite/tests/typecheck/should_fail/FDsFromGivens.stderr +++ b/testsuite/tests/typecheck/should_fail/FDsFromGivens.stderr @@ -1,10 +1,12 @@ -
-FDsFromGivens.hs:21:15:
- Could not deduce (C Char [a]) arising from a use of ‘f’
- from the context (C Char Char)
- bound by a pattern with constructor
- KCC :: C Char Char => () -> KCC,
- in an equation for ‘bar’
- at FDsFromGivens.hs:21:6-10
- In the expression: f
- In an equation for ‘bar’: bar (KCC _) = f
+ +FDsFromGivens.hs:21:15: + Couldn't match type ‘Char’ with ‘[a0]’ + arising from a functional dependency between constraints: + ‘C Char [a0]’ arising from a use of ‘f’ at FDsFromGivens.hs:21:15 + ‘C Char Char’ + arising from a pattern with constructor + KCC :: C Char Char => () -> KCC, + in an equation for ‘bar’ + at FDsFromGivens.hs:21:6-10 + In the expression: f + In an equation for ‘bar’: bar (KCC _) = f diff --git a/testsuite/tests/typecheck/should_fail/T5236.stderr b/testsuite/tests/typecheck/should_fail/T5236.stderr index 557a0413c9..8a723bab9b 100644 --- a/testsuite/tests/typecheck/should_fail/T5236.stderr +++ b/testsuite/tests/typecheck/should_fail/T5236.stderr @@ -1,5 +1,10 @@ -
-T5236.hs:17:5:
- No instance for (Id A B) arising from a use of ‘loop’
- In the expression: loop
- In an equation for ‘f’: f = loop
+ +T5236.hs:13:9: + Couldn't match type ‘A’ with ‘B’ + arising from a functional dependency between: + constraint ‘Id A B’ + arising from the type signature for loop :: Id A B => Bool + instance ‘Id A A’ at T5236.hs:10:10-15 + In the ambiguity check for: Id A B => Bool + To defer the ambiguity check to use sites, enable AllowAmbiguousTypes + In the type signature for ‘loop’: loop :: Id A B => Bool diff --git a/testsuite/tests/typecheck/should_fail/T5978.stderr b/testsuite/tests/typecheck/should_fail/T5978.stderr index db6b8f355e..263e68ba2d 100644 --- a/testsuite/tests/typecheck/should_fail/T5978.stderr +++ b/testsuite/tests/typecheck/should_fail/T5978.stderr @@ -1,5 +1,8 @@ -
-T5978.hs:22:11:
- No instance for (C Double Char) arising from a use of ‘polyBar’
- In the expression: polyBar id monoFoo
- In an equation for ‘monoBar’: monoBar = polyBar id monoFoo
+ +T5978.hs:22:11: + Couldn't match type ‘Bool’ with ‘Char’ + arising from a functional dependency between: + constraint ‘C Double Char’ arising from a use of ‘polyBar’ + instance ‘C Double Bool’ at T5978.hs:8:10-22 + In the expression: polyBar id monoFoo + In an equation for ‘monoBar’: monoBar = polyBar id monoFoo diff --git a/testsuite/tests/typecheck/should_fail/T9612.hs b/testsuite/tests/typecheck/should_fail/T9612.hs new file mode 100644 index 0000000000..a332c47b04 --- /dev/null +++ b/testsuite/tests/typecheck/should_fail/T9612.hs @@ -0,0 +1,20 @@ +{-# LANGUAGE FlexibleInstances, FunctionalDependencies, MultiParamTypeClasses #-} +module T9612 where +import Data.Monoid +import Control.Monad.Trans.Writer.Lazy( Writer, WriterT ) +import Data.Functor.Identity( Identity ) + +class (Monoid w, Monad m) => MonadWriter w m | m -> w where + writer :: (a,w) -> m a + tell :: w -> m () + listen :: m a -> m (a, w) + pass :: m (a, w -> w) -> m a + +f ::(Eq a) => a -> (Int, a) -> Writer [(Int, a)] (Int, a) +f y (n,x) {- | y == x = return (n+1, x) + | otherwise = -} + = do tell (n,x) + return (1,y) + + +instance (Monoid w, Monad m) => MonadWriter w (WriterT w m) where diff --git a/testsuite/tests/typecheck/should_fail/T9612.stderr b/testsuite/tests/typecheck/should_fail/T9612.stderr new file mode 100644 index 0000000000..823fee112c --- /dev/null +++ b/testsuite/tests/typecheck/should_fail/T9612.stderr @@ -0,0 +1,20 @@ + +T9612.hs:16:9: + Couldn't match type ‘[(Int, a)]’ with ‘(Int, a)’ + arising from a functional dependency between: + constraint ‘MonadWriter (Int, a) (WriterT [(Int, a)] Identity)’ + arising from a use of ‘tell’ + instance ‘MonadWriter w (WriterT w m)’ at T9612.hs:20:10-59 + Relevant bindings include + x :: a (bound at T9612.hs:14:8) + y :: a (bound at T9612.hs:14:3) + f :: a -> (Int, a) -> Writer [(Int, a)] (Int, a) + (bound at T9612.hs:14:1) + In a stmt of a 'do' block: tell (n, x) + In the expression: + do { tell (n, x); + return (1, y) } + In an equation for ‘f’: + f y (n, x) + = do { tell (n, x); + return (1, y) } diff --git a/testsuite/tests/typecheck/should_fail/all.T b/testsuite/tests/typecheck/should_fail/all.T index 4f001f5ab7..431a9ba767 100644 --- a/testsuite/tests/typecheck/should_fail/all.T +++ b/testsuite/tests/typecheck/should_fail/all.T @@ -334,3 +334,4 @@ test('T9196', normal, compile_fail, ['']) test('T9305', normal, compile_fail, ['']) test('T9323', normal, compile_fail, ['']) test('T9415', normal, compile_fail, ['']) +test('T9612', normal, compile_fail, ['']) diff --git a/testsuite/tests/typecheck/should_fail/tcfail143.stderr b/testsuite/tests/typecheck/should_fail/tcfail143.stderr index 394fa43c4e..b36d7a8b37 100644 --- a/testsuite/tests/typecheck/should_fail/tcfail143.stderr +++ b/testsuite/tests/typecheck/should_fail/tcfail143.stderr @@ -1,5 +1,8 @@ -
-tcfail143.hs:29:9:
- No instance for (MinMax (S Z) Z Z Z) arising from a use of ‘extend’
- In the expression: n1 `extend` n0
- In an equation for ‘t2’: t2 = n1 `extend` n0
+ +tcfail143.hs:29:9: + Couldn't match type ‘S Z’ with ‘Z’ + arising from a functional dependency between: + constraint ‘MinMax (S Z) Z Z Z’ arising from a use of ‘extend’ + instance ‘MinMax a Z Z a’ at tcfail143.hs:11:10-23 + In the expression: n1 `extend` n0 + In an equation for ‘t2’: t2 = n1 `extend` n0 |