[commit: ghc] master: Add suggestion for PatternSynonyms parse error (fixes #12429) (4b1f072)
git at git.haskell.org
git at git.haskell.org
Fri Mar 3 00:58:44 UTC 2017
Repository : ssh://git@git.haskell.org/ghc
On branch : master
Link : http://ghc.haskell.org/trac/ghc/changeset/4b1f0721ce164d079848d1f8890630dbbf4cbf7a/ghc
>---------------------------------------------------------------
commit 4b1f0721ce164d079848d1f8890630dbbf4cbf7a
Author: Rupert Horlick <ruperthorlick at gmail.com>
Date: Thu Mar 2 16:35:31 2017 -0500
Add suggestion for PatternSynonyms parse error (fixes #12429)
Reviewers: austin, bgamari
Reviewed By: bgamari
Subscribers: thomie
Differential Revision: https://phabricator.haskell.org/D3261
>---------------------------------------------------------------
4b1f0721ce164d079848d1f8890630dbbf4cbf7a
compiler/parser/Lexer.x | 4 ++++
testsuite/tests/parser/should_fail/T12429.hs | 3 +++
testsuite/tests/parser/should_fail/T12429.stderr | 7 +++++++
testsuite/tests/parser/should_fail/all.T | 1 +
4 files changed, 15 insertions(+)
diff --git a/compiler/parser/Lexer.x b/compiler/parser/Lexer.x
index 3c5d98d..6f91f44 100644
--- a/compiler/parser/Lexer.x
+++ b/compiler/parser/Lexer.x
@@ -2394,8 +2394,12 @@ srcParseErr options buf len
$$ ppWhen (token == "=")
(text "Perhaps you need a 'let' in a 'do' block?"
$$ text "e.g. 'let x = 5' instead of 'x = 5'")
+ $$ ppWhen (not ps_enabled && pattern == "pattern") -- #12429
+ (text "Perhaps you intended to use PatternSynonyms")
where token = lexemeToString (offsetBytes (-len) buf) len
+ pattern = lexemeToString (offsetBytes (-len - 8) buf) 7
th_enabled = extopt LangExt.TemplateHaskell options
+ ps_enabled = extopt LangExt.PatternSynonyms options
-- Report a parse failure, giving the span of the previous token as
-- the location of the error. This is the entry point for errors
diff --git a/testsuite/tests/parser/should_fail/T12429.hs b/testsuite/tests/parser/should_fail/T12429.hs
new file mode 100644
index 0000000..3e0496b
--- /dev/null
+++ b/testsuite/tests/parser/should_fail/T12429.hs
@@ -0,0 +1,3 @@
+module X where
+ import Data.Text (pattern Y)
+ x = 3
diff --git a/testsuite/tests/parser/should_fail/T12429.stderr b/testsuite/tests/parser/should_fail/T12429.stderr
new file mode 100644
index 0000000..fde11ec
--- /dev/null
+++ b/testsuite/tests/parser/should_fail/T12429.stderr
@@ -0,0 +1,7 @@
+
+testsuite/tests/parser/should_fail/T12429.hs:2:29: error:
+ parse error on input ‘Y’
+ Perhaps you intended to use PatternSynonyms
+ |
+2 | import Data.Text (pattern Y)
+ | ^
diff --git a/testsuite/tests/parser/should_fail/all.T b/testsuite/tests/parser/should_fail/all.T
index ca23d3b..e515e2f 100644
--- a/testsuite/tests/parser/should_fail/all.T
+++ b/testsuite/tests/parser/should_fail/all.T
@@ -94,3 +94,4 @@ test('T10196Fail2', normal, compile_fail, [''])
test('T10498a', normal, compile_fail, [''])
test('T10498b', normal, compile_fail, [''])
test('T12051', normal, compile_fail, [''])
+test('T12429', normal, compile_fail, [''])
More information about the ghc-commits
mailing list