diff options
author | Simon Peyton Jones <simonpj@microsoft.com> | 2016-04-21 13:06:54 +0100 |
---|---|---|
committer | Simon Peyton Jones <simonpj@microsoft.com> | 2016-04-22 11:32:31 +0100 |
commit | 9421b0c77122d40bf72665ea9f90dca64a0a0ae2 (patch) | |
tree | e6a76ff1e6f6dab8590086d7ef89fc54bb842a0b /testsuite/tests/ghci | |
parent | edf54d72b5b8a6dd0deafa036dc16dcfc3fcb29f (diff) | |
download | haskell-9421b0c77122d40bf72665ea9f90dca64a0a0ae2.tar.gz |
Warn about simplifiable class constraints
Provoked by Trac #11948, this patch adds a new warning to GHC
-Wsimplifiable-class-constraints
It warns if you write a class constraint in a type signature that
can be simplified by an existing instance declaration. Almost always
this means you should simplify it right now; type inference is very
fragile without it, as #11948 shows.
I've put the warning as on-by-default, but I suppose that if there are
howls of protest we can move it out (as happened for -Wredundant-constraints.
It actually found an example of an over-complicated context in CmmNode.
Quite a few tests use these weird contexts to trigger something else,
so I had to suppress the warning in those.
The 'haskeline' library has a few occurrences of the warning (which
I think should be fixed), so I switched it off for that library in
warnings.mk.
The warning itself is done in TcValidity.check_class_pred.
HOWEVER, when type inference fails we get a type error; and the error
suppresses the (informative) warning. So as things stand, the warning
only happens when it doesn't cause a problem. Not sure what to do
about this, but this patch takes us forward, I think.
Diffstat (limited to 'testsuite/tests/ghci')
-rw-r--r-- | testsuite/tests/ghci/scripts/ghci047.script | 4 | ||||
-rw-r--r-- | testsuite/tests/ghci/scripts/ghci047.stderr | 4 |
2 files changed, 5 insertions, 3 deletions
diff --git a/testsuite/tests/ghci/scripts/ghci047.script b/testsuite/tests/ghci/scripts/ghci047.script index d1ceefd482..b30245b3af 100644 --- a/testsuite/tests/ghci/scripts/ghci047.script +++ b/testsuite/tests/ghci/scripts/ghci047.script @@ -1,5 +1,6 @@ --Testing GADTs, type families as well as a ton of crazy type stuff -:set -fno-warn-redundant-constraints +:set -Wno-redundant-constraints +:set -Wno-simplifiable-class-constraints :set -XGADTs :set -XTypeFamilies :set -XFunctionalDependencies @@ -33,6 +34,7 @@ type instance Or HFalse HTrue = HTrue type instance Or HFalse HFalse = HFalse let f :: (Or a c ~ HTrue, TypeEq t A a, TypeEq t C c) => ABorC t -> Int ; f x = 1 +-- Weird test case: (TypeEq t C c) and (TypeEq t C c) are both simplifiable f $ Foo 1 f $ Bar True f $ Baz 'a' diff --git a/testsuite/tests/ghci/scripts/ghci047.stderr b/testsuite/tests/ghci/scripts/ghci047.stderr index badfc1ebb1..86130800b0 100644 --- a/testsuite/tests/ghci/scripts/ghci047.stderr +++ b/testsuite/tests/ghci/scripts/ghci047.stderr @@ -1,11 +1,11 @@ -<interactive>:38:1: error: +<interactive>:40:1: error: • Couldn't match type ‘HFalse’ with ‘HTrue’ arising from a use of ‘f’ • In the expression: f $ Baz 'a' In an equation for ‘it’: it = f $ Baz 'a' -<interactive>:39:1: error: +<interactive>:41:1: error: • Couldn't match type ‘HFalse’ with ‘HTrue’ arising from a use of ‘f’ • In the expression: f $ Quz |