summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorVladislav Zavialov <vlad.z.4096@gmail.com>2021-03-08 23:36:26 +0300
committerVladislav Zavialov <vlad.z.4096@gmail.com>2021-03-11 00:19:30 +0300
commit8a8bb7eda5b1f0be5ac95dd3af7a3430e0212f80 (patch)
tree90281a21ebdcf54e8eb2786dfb49c72a54d1cbb1
parenta971c62f1b1b9dbd062584ab97a837cbc5c3d43b (diff)
downloadhaskell-8a8bb7eda5b1f0be5ac95dd3af7a3430e0212f80.tar.gz
Location for tuple section pattern error (#19504)wip/backport-8.10-19504
This fixes a regression that led to loss of location information in error messages about the use of tuple sections in patterns. (cherry picked from commit df8e8ba267ffd7b8be0702bd64b8c39532359461)
-rw-r--r--compiler/parser/RdrHsSyn.hs4
-rw-r--r--testsuite/tests/parser/should_fail/T19504.hs3
-rw-r--r--testsuite/tests/parser/should_fail/T19504.stderr2
-rw-r--r--testsuite/tests/parser/should_fail/all.T1
4 files changed, 9 insertions, 1 deletions
diff --git a/compiler/parser/RdrHsSyn.hs b/compiler/parser/RdrHsSyn.hs
index f7a0d0fb22..2782fb69fb 100644
--- a/compiler/parser/RdrHsSyn.hs
+++ b/compiler/parser/RdrHsSyn.hs
@@ -3241,7 +3241,9 @@ mkSumOrTuplePat l boxity (Tuple ps) = do
return $ cL l (PatBuilderPat (TuplePat noExtField ps' boxity))
where
toTupPat :: Located (Maybe (Located (PatBuilder GhcPs))) -> PV (LPat GhcPs)
- toTupPat (dL -> L l p) = case p of
+ -- Ignore the element location so that the error message refers to the
+ -- entire tuple. See #19504 (and the discussion) for details.
+ toTupPat (dL -> L _ p) = case p of
Nothing -> addFatalError l (text "Tuple section in pattern context")
Just p' -> checkLPat p'
diff --git a/testsuite/tests/parser/should_fail/T19504.hs b/testsuite/tests/parser/should_fail/T19504.hs
new file mode 100644
index 0000000000..033f13e4db
--- /dev/null
+++ b/testsuite/tests/parser/should_fail/T19504.hs
@@ -0,0 +1,3 @@
+module T19504 where
+
+error_notLocated = (\ (0, ) -> (0, undefined))
diff --git a/testsuite/tests/parser/should_fail/T19504.stderr b/testsuite/tests/parser/should_fail/T19504.stderr
new file mode 100644
index 0000000000..9d37ba22a0
--- /dev/null
+++ b/testsuite/tests/parser/should_fail/T19504.stderr
@@ -0,0 +1,2 @@
+
+T19504.hs:3:23: error: Tuple section in pattern context
diff --git a/testsuite/tests/parser/should_fail/all.T b/testsuite/tests/parser/should_fail/all.T
index 2fc7f3d326..ef4cdff1f7 100644
--- a/testsuite/tests/parser/should_fail/all.T
+++ b/testsuite/tests/parser/should_fail/all.T
@@ -161,3 +161,4 @@ test('patFail006', normal, compile_fail, [''])
test('patFail007', normal, compile_fail, [''])
test('patFail008', normal, compile_fail, [''])
test('patFail009', normal, compile_fail, [''])
+test('T19504', normal, compile_fail, [''])