summaryrefslogtreecommitdiff
path: root/testsuite
diff options
context:
space:
mode:
authorÖmer Sinan Ağacan <omeragacan@gmail.com>2018-03-14 09:16:51 +0300
committerÖmer Sinan Ağacan <omeragacan@gmail.com>2018-03-14 09:17:11 +0300
commitcb6d8589c83247ec96d5faa82df3e93f419bbfe0 (patch)
tree99b60cf2f7f03d9fc25040390a2f1d7b2b236d42 /testsuite
parent152055a19cf368439c8450040b68142f8e7d0346 (diff)
downloadhaskell-cb6d8589c83247ec96d5faa82df3e93f419bbfe0.tar.gz
Slighly improve infix con app pattern errors
Given this program: main = do f $ do a <- return 3 c <- do return 5 GHC previously gave this error message: Main.hs:2:7: error: Parse error in pattern: do a <- return 3 c Possibly caused by a missing 'do'? | 2 | f $ do | ^^... What happened is GHC considered the whole `f $ do a <- return 3 c` as a pattern. When parsed as an expression it becomes an infix application of `($)`, and GHC checks left and right hand sides before checking if `($)` is a valid infix constructor name, and shows the first error it got. If instead we first check if the infix op is valid in pattern context, the error message becomes much clearer: Main.hs:2:3: error: Parse error in pattern: f $ do a <- return 3 c Possibly caused by a missing 'do'? | 2 | f $ do | ^^^^^^... This may not entirely fix #11188 but I think it's an improvement. Reviewers: bgamari Reviewed By: bgamari Subscribers: rwbarton, thomie, carter GHC Trac Issues: #11188 Differential Revision: https://phabricator.haskell.org/D4497
Diffstat (limited to 'testsuite')
-rw-r--r--testsuite/tests/parser/should_fail/InfixAppPatErr.hs5
-rw-r--r--testsuite/tests/parser/should_fail/InfixAppPatErr.stderr4
-rw-r--r--testsuite/tests/parser/should_fail/all.T2
3 files changed, 11 insertions, 0 deletions
diff --git a/testsuite/tests/parser/should_fail/InfixAppPatErr.hs b/testsuite/tests/parser/should_fail/InfixAppPatErr.hs
new file mode 100644
index 0000000000..5a56f711eb
--- /dev/null
+++ b/testsuite/tests/parser/should_fail/InfixAppPatErr.hs
@@ -0,0 +1,5 @@
+main = do
+ f $ do
+ a <- return 3
+ c <- do
+ return 5
diff --git a/testsuite/tests/parser/should_fail/InfixAppPatErr.stderr b/testsuite/tests/parser/should_fail/InfixAppPatErr.stderr
new file mode 100644
index 0000000000..69839e3920
--- /dev/null
+++ b/testsuite/tests/parser/should_fail/InfixAppPatErr.stderr
@@ -0,0 +1,4 @@
+
+InfixAppPatErr.hs:2:3: error:
+ Parse error in pattern: f $ do a <- return 3 c
+ Possibly caused by a missing 'do'?
diff --git a/testsuite/tests/parser/should_fail/all.T b/testsuite/tests/parser/should_fail/all.T
index 2cb9c49de2..d47e0f5796 100644
--- a/testsuite/tests/parser/should_fail/all.T
+++ b/testsuite/tests/parser/should_fail/all.T
@@ -115,3 +115,5 @@ test('NumericUnderscoresFail0',
grep_errmsg(r'^NumericUnderscoresFail0.hs:'), compile_fail, [''])
test('NumericUnderscoresFail1',
grep_errmsg(r'^NumericUnderscoresFail1.hs:'), compile_fail, [''])
+
+test('InfixAppPatErr', normal, compile_fail, [''])