[commit: ghc] wip/ghc-8.8-merges: Fix #15849 by checking whether there's a do block (3ac4232)

git at git.haskell.org git at git.haskell.org
Thu Feb 21 15:11:12 UTC 2019


Repository : ssh://git@git.haskell.org/ghc

On branch  : wip/ghc-8.8-merges
Link       : http://ghc.haskell.org/trac/ghc/changeset/3ac42326d7185e74fdf7529e5a589cade60093d2/ghc

>---------------------------------------------------------------

commit 3ac42326d7185e74fdf7529e5a589cade60093d2
Author: nineonine <mail4chemik at gmail.com>
Date:   Sat Feb 9 00:20:19 2019 -0800

    Fix #15849 by checking whether there's a do block
    
    (cherry picked from commit a08f463bcc9727d91cec4c6e952ad0f5bbc3fbf9)


>---------------------------------------------------------------

3ac42326d7185e74fdf7529e5a589cade60093d2
 compiler/parser/Lexer.x                               | 3 ++-
 testsuite/tests/parser/should_fail/T15849.hs          | 4 ++++
 testsuite/tests/parser/should_fail/T15849.stderr      | 3 +++
 testsuite/tests/parser/should_fail/all.T              | 1 +
 testsuite/tests/parser/should_fail/readFail011.stderr | 2 --
 testsuite/tests/parser/should_fail/readFail034.stderr | 2 --
 6 files changed, 10 insertions(+), 5 deletions(-)

diff --git a/compiler/parser/Lexer.x b/compiler/parser/Lexer.x
index 4ba50c1..147e678 100644
--- a/compiler/parser/Lexer.x
+++ b/compiler/parser/Lexer.x
@@ -2574,7 +2574,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
@@ -2582,6 +2582,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
index 0000000..eea8e4f
--- /dev/null
+++ b/testsuite/tests/parser/should_fail/T15849.hs
@@ -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
index 0000000..e974dbd
--- /dev/null
+++ b/testsuite/tests/parser/should_fail/T15849.stderr
@@ -0,0 +1,3 @@
+
+T15849.hs:4:6: error:
+    parse error on input ‘=’
diff --git a/testsuite/tests/parser/should_fail/all.T b/testsuite/tests/parser/should_fail/all.T
index 2d7c241..a8d685c 100644
--- a/testsuite/tests/parser/should_fail/all.T
+++ b/testsuite/tests/parser/should_fail/all.T
@@ -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, [''])
diff --git a/testsuite/tests/parser/should_fail/readFail011.stderr b/testsuite/tests/parser/should_fail/readFail011.stderr
index 25accd2..08388e5 100644
--- a/testsuite/tests/parser/should_fail/readFail011.stderr
+++ b/testsuite/tests/parser/should_fail/readFail011.stderr
@@ -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'
diff --git a/testsuite/tests/parser/should_fail/readFail034.stderr b/testsuite/tests/parser/should_fail/readFail034.stderr
index 75156c9..ad2fb00 100644
--- a/testsuite/tests/parser/should_fail/readFail034.stderr
+++ b/testsuite/tests/parser/should_fail/readFail034.stderr
@@ -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'



More information about the ghc-commits mailing list