Add suggestion for PatternSynonyms parse error (fixes #12429)
authorRupert Horlick <ruperthorlick@gmail.com>
Thu, 2 Mar 2017 21:35:31 +0000 (16:35 -0500)
committerBen Gamari <ben@smart-cactus.org>
Fri, 3 Mar 2017 00:58:01 +0000 (19:58 -0500)
Reviewers: austin, bgamari

Reviewed By: bgamari

Subscribers: thomie

Differential Revision: https://phabricator.haskell.org/D3261

compiler/parser/Lexer.x
testsuite/tests/parser/should_fail/T12429.hs [new file with mode: 0644]
testsuite/tests/parser/should_fail/T12429.stderr [new file with mode: 0644]
testsuite/tests/parser/should_fail/all.T

index 3c5d98d..6f91f44 100644 (file)
@@ -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 (file)
index 0000000..3e0496b
--- /dev/null
@@ -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 (file)
index 0000000..fde11ec
--- /dev/null
@@ -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)
+  |                             ^
index ca23d3b..e515e2f 100644 (file)
@@ -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, [''])