summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMatthew Pickering <matthewtpickering@gmail.com>2022-12-01 17:43:40 +0000
committerZubin Duggal <zubin.duggal@gmail.com>2023-02-07 18:47:09 +0530
commit52e579b610ba3fe59a56596c88b560f3659bd73f (patch)
tree0a7524f22186c259185340729b378f594aa946fd
parenta090f5c3d4376810617237ff5be589fafc0d96b6 (diff)
downloadhaskell-52e579b610ba3fe59a56596c88b560f3659bd73f.tar.gz
ApplicativeDo: Set pattern location before running exhaustiveness checker
This improves the error messages of the exhaustiveness checker when checking statements which have been moved around with ApplicativeDo. Before: Test.hs:2:3: warning: [GHC-62161] [-Wincomplete-uni-patterns] Pattern match(es) are non-exhaustive In a pattern binding: Patterns of type ‘Maybe ()’ not matched: Nothing | 2 | let x = () | ^^^^^^^^^^ After: Test.hs:4:3: warning: [GHC-62161] [-Wincomplete-uni-patterns] Pattern match(es) are non-exhaustive In a pattern binding: Patterns of type ‘Maybe ()’ not matched: Nothing | 4 | ~(Just res1) <- seq x (pure $ Nothing @()) | Fixes #22483 (cherry picked from commit 74c767df770766d8d52e87b9ff7da10f94620a91) (cherry picked from commit 51c6051bcc405bc1dbddd450ade949acd70db6b8)
-rw-r--r--compiler/GHC/HsToCore/Expr.hs3
-rw-r--r--testsuite/tests/ado/T22483.hs7
-rw-r--r--testsuite/tests/ado/T22483.stderr8
-rw-r--r--testsuite/tests/ado/all.T1
4 files changed, 18 insertions, 1 deletions
diff --git a/compiler/GHC/HsToCore/Expr.hs b/compiler/GHC/HsToCore/Expr.hs
index 9ce903286d..b6fe849e14 100644
--- a/compiler/GHC/HsToCore/Expr.hs
+++ b/compiler/GHC/HsToCore/Expr.hs
@@ -984,7 +984,8 @@ dsDo ctx stmts
; body' <- dsLExpr $ noLocA $ HsDo body_ty ctx (noLocA stmts)
; let match_args (pat, fail_op) (vs,body)
- = do { var <- selectSimpleMatchVarL Many pat
+ = putSrcSpanDs (getLocA pat) $
+ do { var <- selectSimpleMatchVarL Many pat
; match <- matchSinglePatVar var Nothing (StmtCtxt ctx) pat
body_ty (cantFailMatchResult body)
; match_code <- dsHandleMonadicFailure ctx pat match fail_op
diff --git a/testsuite/tests/ado/T22483.hs b/testsuite/tests/ado/T22483.hs
new file mode 100644
index 0000000000..31d2f72add
--- /dev/null
+++ b/testsuite/tests/ado/T22483.hs
@@ -0,0 +1,7 @@
+main = do
+ let x = ()
+ res2 <- pure ()
+ ~(Just res1) <- seq x (pure $ Nothing @())
+ print res1
+ print res2
+ pure ()
diff --git a/testsuite/tests/ado/T22483.stderr b/testsuite/tests/ado/T22483.stderr
new file mode 100644
index 0000000000..7aa274a992
--- /dev/null
+++ b/testsuite/tests/ado/T22483.stderr
@@ -0,0 +1,8 @@
+
+T22483.hs:1:1: warning: [-Wmissing-signatures (in -Wall)]
+ Top-level binding with no type signature: main :: IO ()
+
+T22483.hs:4:3: warning: [-Wincomplete-uni-patterns (in -Wall)]
+ Pattern match(es) are non-exhaustive
+ In a pattern binding:
+ Patterns of type ‘Maybe ()’ not matched: Nothing
diff --git a/testsuite/tests/ado/all.T b/testsuite/tests/ado/all.T
index 8c07539965..58e8c26a81 100644
--- a/testsuite/tests/ado/all.T
+++ b/testsuite/tests/ado/all.T
@@ -18,3 +18,4 @@ test('T14163', normal, compile_and_run, [''])
test('T15344', normal, compile_and_run, [''])
test('T16628', normal, compile_fail, [''])
test('T17835', normal, compile, [''])
+test('T22483', normal, compile, ['-Wall'])