summaryrefslogtreecommitdiff
path: root/testsuite/tests/gadt
diff options
context:
space:
mode:
authorSimon Peyton Jones <simonpj@microsoft.com>2018-08-24 16:40:28 +0100
committerSimon Peyton Jones <simonpj@microsoft.com>2018-08-24 16:47:22 +0100
commitff29fc84c03c800cfa04c2a00eb8edf6fa5f4183 (patch)
tree16660e00d3d8f57af74384eb642a3723b45f4f4e /testsuite/tests/gadt
parent4b79329f24dfdf907f223ff9fc41c77d9df86e04 (diff)
downloadhaskell-ff29fc84c03c800cfa04c2a00eb8edf6fa5f4183.tar.gz
Better error reporting for inaccessible code
This patch fixes Trac #15558. There turned out to be two distinct problems * In TcExpr.tc_poly_expr_nc we had tc_poly_expr_nc (L loc expr) res_ty = do { traceTc "tcPolyExprNC" (ppr res_ty) ; (wrap, expr') <- tcSkolemiseET GenSigCtxt res_ty $ \ res_ty -> setSrcSpan loc $ -- NB: setSrcSpan *after* skolemising, -- so we get better skolem locations tcExpr expr res_ty Putting the setSrcSpan inside the tcSkolemise means that the location on the Implication constraint is the /call/ to the function rather than the /argument/ to the call, and that is really quite wrong. I don't know what Richard's comment NB means -- I moved the setSrcSpan outside, and the "binding site" info in error messages actually improved. The reason I found this is that it affects the span reported for Trac #15558. * In TcErrors.mkGivenErrorReporter we carefully munge the location for an insoluble Given constraint (Note [Inaccessible code]). But the 'implic' passed in wasn't necesarily the immediately- enclosing implication -- but for location-munging purposes it jolly well should be. Solution: use the innermost implication. This actually simplifies the code -- no need to pass an implication in to mkGivenErrorReporter.
Diffstat (limited to 'testsuite/tests/gadt')
-rw-r--r--testsuite/tests/gadt/T15558.hs14
-rw-r--r--testsuite/tests/gadt/T15558.stderr9
-rw-r--r--testsuite/tests/gadt/all.T1
3 files changed, 24 insertions, 0 deletions
diff --git a/testsuite/tests/gadt/T15558.hs b/testsuite/tests/gadt/T15558.hs
new file mode 100644
index 0000000000..91dff3f956
--- /dev/null
+++ b/testsuite/tests/gadt/T15558.hs
@@ -0,0 +1,14 @@
+{-# LANGUAGE GADTs #-}
+{-# LANGUAGE RankNTypes #-}
+module T15558 where
+
+data T a where
+ MkT :: T Int
+
+data Foo a = MkFoo ((a ~ Bool) => ())
+
+f :: T a -> Foo a
+f MkT = MkFoo ()
+
+-- g :: Foo Int
+-- g = f MkT
diff --git a/testsuite/tests/gadt/T15558.stderr b/testsuite/tests/gadt/T15558.stderr
new file mode 100644
index 0000000000..ee70f0373b
--- /dev/null
+++ b/testsuite/tests/gadt/T15558.stderr
@@ -0,0 +1,9 @@
+
+T15558.hs:11:15: warning: [-Winaccessible-code (in -Wdefault)]
+ • Couldn't match type ‘Int’ with ‘Bool’
+ Inaccessible code in
+ a type expected by the context:
+ (a ~ Bool) => ()
+ • In the first argument of ‘MkFoo’, namely ‘()’
+ In the expression: MkFoo ()
+ In an equation for ‘f’: f MkT = MkFoo ()
diff --git a/testsuite/tests/gadt/all.T b/testsuite/tests/gadt/all.T
index 27210312c3..395cce8c12 100644
--- a/testsuite/tests/gadt/all.T
+++ b/testsuite/tests/gadt/all.T
@@ -118,3 +118,4 @@ test('T14320', normal, compile, [''])
test('T14719', normal, compile_fail, ['-fdiagnostics-show-caret'])
test('T14808', normal, compile, [''])
test('T15009', normal, compile, [''])
+test('T15558', normal, compile, [''])