Fix #15849 by checking whether there's a do block
authornineonine <mail4chemik@gmail.com>
Sat, 9 Feb 2019 08:20:19 +0000 (00:20 -0800)
committerMarge Bot <ben+marge-bot@smart-cactus.org>
Wed, 13 Feb 2019 00:48:38 +0000 (19:48 -0500)
compiler/parser/Lexer.x
testsuite/tests/parser/should_fail/T15849.hs [new file with mode: 0644]
testsuite/tests/parser/should_fail/T15849.stderr [new file with mode: 0644]
testsuite/tests/parser/should_fail/all.T
testsuite/tests/parser/should_fail/readFail011.stderr
testsuite/tests/parser/should_fail/readFail034.stderr

index 1e27158..929a6a6 100644 (file)
@@ -2585,7 +2585,7 @@ srcParseErr options buf len
                         (if mdoInLast100
                            then text "Perhaps you intended to use RecursiveDo"
                            else text "Perhaps this statement should be within a 'do' block?")
-              $$ ppWhen (token == "=")
+              $$ ppWhen (token == "=" && doInLast100) -- #15849
                         (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
@@ -2593,6 +2593,7 @@ srcParseErr options buf len
   where token = lexemeToString (offsetBytes (-len) buf) len
         pattern = decodePrevNChars 8 buf
         last100 = decodePrevNChars 100 buf
+        doInLast100 = "do" `isInfixOf` last100
         mdoInLast100 = "mdo" `isInfixOf` last100
         th_enabled = ThBit `xtest` pExtsBitmap options
         ps_enabled = PatternSynonymsBit `xtest` pExtsBitmap options
diff --git a/testsuite/tests/parser/should_fail/T15849.hs b/testsuite/tests/parser/should_fail/T15849.hs
new file mode 100644 (file)
index 0000000..eea8e4f
--- /dev/null
@@ -0,0 +1,4 @@
+module T15849 where
+
+main = return ()
+ foo = return ()
diff --git a/testsuite/tests/parser/should_fail/T15849.stderr b/testsuite/tests/parser/should_fail/T15849.stderr
new file mode 100644 (file)
index 0000000..e974dbd
--- /dev/null
@@ -0,0 +1,3 @@
+
+T15849.hs:4:6: error:
+    parse error on input ‘=’
index ad23574..7976c17 100644 (file)
@@ -133,6 +133,7 @@ test('typeops_C', normal, compile_fail, [''])
 test('typeops_D', normal, compile_fail, [''])
 test('T15053', normal, compile_fail, [''])
 test('T15233', normal, compile_fail, [''])
+test('T15849', normal, compile_fail, [''])
 test('typeopsDataCon_A', normal, compile_fail, [''])
 test('typeopsDataCon_B', normal, compile_fail, [''])
 test('strictnessDataCon_A', normal, compile_fail, [''])
index 25accd2..08388e5 100644 (file)
@@ -1,5 +1,3 @@
 
 readFail011.hs:7:10: error:
     parse error on input ‘=’
-    Perhaps you need a 'let' in a 'do' block?
-    e.g. 'let x = 5' instead of 'x = 5'
index 75156c9..ad2fb00 100644 (file)
@@ -1,5 +1,3 @@
 
 readFail034.hs:4:6: error:
     parse error on input ‘=’
-    Perhaps you need a 'let' in a 'do' block?
-    e.g. 'let x = 5' instead of 'x = 5'