[commit: ghc] wip/forall-keyword, wip/hadrian-wcompat, wip/no-kind-vars: Fix #15849 by checking whether there's a do block (a08f463)

git at git.haskell.org git at git.haskell.org
Thu Feb 14 09:12:39 UTC 2019


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

On branches: wip/forall-keyword,wip/hadrian-wcompat,wip/no-kind-vars
Link       : http://ghc.haskell.org/trac/ghc/changeset/a08f463bcc9727d91cec4c6e952ad0f5bbc3fbf9/ghc

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

commit a08f463bcc9727d91cec4c6e952ad0f5bbc3fbf9
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


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

a08f463bcc9727d91cec4c6e952ad0f5bbc3fbf9
 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 1e27158..929a6a6 100644
--- a/compiler/parser/Lexer.x
+++ b/compiler/parser/Lexer.x
@@ -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
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 ad23574..7976c17 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