From 4b638dda50a024a6361f0877aed6da0b5d4c604c Mon Sep 17 00:00:00 2001 From: Vladislav Zavialov Date: Mon, 8 Mar 2021 23:36:26 +0300 Subject: Location for tuple section pattern error (#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) --- compiler/GHC/Parser/PostProcess.hs | 4 +++- testsuite/tests/parser/should_fail/T19504.hs | 3 +++ testsuite/tests/parser/should_fail/T19504.stderr | 2 ++ testsuite/tests/parser/should_fail/all.T | 1 + 4 files changed, 9 insertions(+), 1 deletion(-) create mode 100644 testsuite/tests/parser/should_fail/T19504.hs create mode 100644 testsuite/tests/parser/should_fail/T19504.stderr diff --git a/compiler/GHC/Parser/PostProcess.hs b/compiler/GHC/Parser/PostProcess.hs index 88e3d04928..8df4b4bd2e 100644 --- a/compiler/GHC/Parser/PostProcess.hs +++ b/compiler/GHC/Parser/PostProcess.hs @@ -3052,7 +3052,9 @@ mkSumOrTuplePat l boxity (Tuple ps) = do return $ L l (PatBuilderPat (TuplePat noExtField ps' boxity)) where toTupPat :: Located (Maybe (Located (PatBuilder GhcPs))) -> PV (LPat GhcPs) - toTupPat (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 (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 9142eb0393..2467e3728e 100644 --- a/testsuite/tests/parser/should_fail/all.T +++ b/testsuite/tests/parser/should_fail/all.T @@ -173,3 +173,4 @@ test('T18251c', normal, compile_fail, ['']) test('T18251d', normal, compile_fail, ['']) test('T18251e', normal, compile_fail, ['']) test('T18251f', normal, compile_fail, ['']) +test('T19504', normal, compile_fail, ['']) -- cgit v1.2.1