diff options
author | nineonine <mail4chemik@gmail.com> | 2019-02-09 00:20:19 -0800 |
---|---|---|
committer | Ben Gamari <ben@smart-cactus.org> | 2019-02-20 14:28:55 -0500 |
commit | 3ac42326d7185e74fdf7529e5a589cade60093d2 (patch) | |
tree | 794a569d61898996ec29614ce15881a8cc55cf1f | |
parent | 3ac2d665efb4aadf62c310710e83a2e945bb25b4 (diff) | |
download | haskell-3ac42326d7185e74fdf7529e5a589cade60093d2.tar.gz |
Fix #15849 by checking whether there's a do block
(cherry picked from commit a08f463bcc9727d91cec4c6e952ad0f5bbc3fbf9)
-rw-r--r-- | compiler/parser/Lexer.x | 3 | ||||
-rw-r--r-- | testsuite/tests/parser/should_fail/T15849.hs | 4 | ||||
-rw-r--r-- | testsuite/tests/parser/should_fail/T15849.stderr | 3 | ||||
-rw-r--r-- | testsuite/tests/parser/should_fail/all.T | 1 | ||||
-rw-r--r-- | testsuite/tests/parser/should_fail/readFail011.stderr | 2 | ||||
-rw-r--r-- | 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 4ba50c1d5b..147e678973 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 0000000000..eea8e4f9c1 --- /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 0000000000..e974dbde02 --- /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 2d7c241ed0..a8d685c47f 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 25accd2a19..08388e5d21 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 75156c9ae4..ad2fb000af 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' |