[commit: ghc] master: Lexer: Suggest adding 'let' on unexpected '=' token (1ff7f09)
git at git.haskell.org
git at git.haskell.org
Tue Jun 16 18:03:40 UTC 2015
Repository : ssh://git@git.haskell.org/ghc
On branch : master
Link : http://ghc.haskell.org/trac/ghc/changeset/1ff7f09b3abedb2a6daf384b55ad3d0134f0d174/ghc
>---------------------------------------------------------------
commit 1ff7f09b3abedb2a6daf384b55ad3d0134f0d174
Author: Ben Gamari <bgamari.foss at gmail.com>
Date: Tue Jun 16 20:01:22 2015 +0200
Lexer: Suggest adding 'let' on unexpected '=' token
Summary:
I've heard numerous fledgling Haskeller's complain about the behavior of
ghci regarding bindings. While most REPLs accept bindings of the form
`x = 42`, GHCi is implicitly a `do` block, meaning that the user must
know to use a `let` to introduce a binding.
Here we suggest to the user that they may need a `let` and give them a
small example in the event that we find an unexpected `=` token.
Reviewers: austin
Reviewed By: austin
Subscribers: thomie, bgamari
Differential Revision: https://phabricator.haskell.org/D980
>---------------------------------------------------------------
1ff7f09b3abedb2a6daf384b55ad3d0134f0d174
compiler/parser/Lexer.x | 3 +++
testsuite/tests/ghci/should_run/T9915.stderr | 5 ++++-
testsuite/tests/parser/should_fail/readFail011.stderr | 5 ++++-
testsuite/tests/parser/should_fail/readFail034.stderr | 5 ++++-
4 files changed, 15 insertions(+), 3 deletions(-)
diff --git a/compiler/parser/Lexer.x b/compiler/parser/Lexer.x
index 1be7245..5839a41 100644
--- a/compiler/parser/Lexer.x
+++ b/compiler/parser/Lexer.x
@@ -2229,6 +2229,9 @@ srcParseErr dflags buf len
(text "Perhaps you intended to use TemplateHaskell")
$$ ppWhen (token == "<-")
(text "Perhaps this statement should be within a 'do' block?")
+ $$ ppWhen (token == "=")
+ (text "Perhaps you need a 'let' in a 'do' block?"
+ $$ text "e.g. 'let x = 5' instead of 'x = 5'")
where token = lexemeToString (offsetBytes (-len) buf) len
th_enabled = xopt Opt_TemplateHaskell dflags
diff --git a/testsuite/tests/ghci/should_run/T9915.stderr b/testsuite/tests/ghci/should_run/T9915.stderr
index de2c5cb..333f17a 100644
--- a/testsuite/tests/ghci/should_run/T9915.stderr
+++ b/testsuite/tests/ghci/should_run/T9915.stderr
@@ -1,2 +1,5 @@
-<interactive>:3:9: parse error on input ‘=’
+<interactive>:3:9: 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/readFail011.stderr b/testsuite/tests/parser/should_fail/readFail011.stderr
index 5c5504b..25accd2 100644
--- a/testsuite/tests/parser/should_fail/readFail011.stderr
+++ b/testsuite/tests/parser/should_fail/readFail011.stderr
@@ -1,2 +1,5 @@
-readFail011.hs:7:10: parse error on input ‘=’
+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 027d0ca..75156c9 100644
--- a/testsuite/tests/parser/should_fail/readFail034.stderr
+++ b/testsuite/tests/parser/should_fail/readFail034.stderr
@@ -1,2 +1,5 @@
-readFail034.hs:4:6: parse error on input ‘=’
+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