From 92c924e07dfef327509555c27a5478d9851ec9fa Mon Sep 17 00:00:00 2001 From: Thomas Miedema <thomasmiedema@gmail.com> Date: Wed, 7 Oct 2015 20:36:54 -0500 Subject: [PATCH] Parser: revert some error messages to what they were before 7.10 Among doing other things, Phab:D201 (bc2289e13d9586be087bd8136943dc35a0130c88) tried to improve the error messages thrown by the parser. For example a missing else clause now prints "parse error in if statement: else clause empty" instead of "parse error (possibly incorrect indentation or mismatched brackets)". Some error messages got much worse however (see tests), and the result seems to be a net negative. Although not entirely satisfactory, this commits therefore reverts those parser changes. Reviewed By: austin Differential Revision: https://phabricator.haskell.org/D1309 GHC Trac Issues: #10498 --- compiler/parser/Parser.y | 31 ------------------- .../should_fail/ParserNoLambdaCase.stderr | 2 +- testsuite/tests/parser/should_fail/T10498a.hs | 14 +++++++++ .../tests/parser/should_fail/T10498a.stderr | 2 ++ testsuite/tests/parser/should_fail/T10498b.hs | 7 +++++ .../tests/parser/should_fail/T10498b.stderr | 2 ++ testsuite/tests/parser/should_fail/all.T | 2 ++ .../parser/should_fail/readFail020.stderr | 3 +- 8 files changed, 29 insertions(+), 34 deletions(-) create mode 100644 testsuite/tests/parser/should_fail/T10498a.hs create mode 100644 testsuite/tests/parser/should_fail/T10498a.stderr create mode 100644 testsuite/tests/parser/should_fail/T10498b.hs create mode 100644 testsuite/tests/parser/should_fail/T10498b.stderr diff --git a/compiler/parser/Parser.y b/compiler/parser/Parser.y index 900620616b63..3ac0da32ccca 100644 --- a/compiler/parser/Parser.y +++ b/compiler/parser/Parser.y @@ -2067,37 +2067,6 @@ exp10 :: { LHsExpr RdrName } -- hdaume: core annotation | fexp { $1 } - -- parsing error messages go below here - | '\\' apat apats opt_asig '->' error {% parseErrorSDoc (combineLocs $1 $5) $ text - "parse error in lambda: no expression after '->'" - } - | '\\' error {% parseErrorSDoc (getLoc $1) $ text - "parse error: naked lambda expression '\'" - } - | 'let' binds 'in' error {% parseErrorSDoc (combineLocs $1 $2) $ text - "parse error in let binding: missing expression after 'in'" - } - | 'let' binds error {% parseErrorSDoc (combineLocs $1 $2) $ text - "parse error in let binding: missing required 'in'" - } - | 'let' error {% parseErrorSDoc (getLoc $1) $ text - "parse error: naked let binding" - } - | 'if' exp optSemi 'then' exp optSemi - 'else' error {% hintIf (combineLocs $1 $5) "else clause empty" } - | 'if' exp optSemi 'then' exp optSemi error {% hintIf (combineLocs $1 $5) "missing required else clause" } - | 'if' exp optSemi 'then' error {% hintIf (combineLocs $1 $2) "then clause empty" } - | 'if' exp optSemi error {% hintIf (combineLocs $1 $2) "missing required then and else clauses" } - | 'if' error {% hintIf (getLoc $1) "naked if statement" } - | 'case' exp 'of' error {% parseErrorSDoc (combineLocs $1 $2) $ text - "parse error in case statement: missing list after '->'" - } - | 'case' exp error {% parseErrorSDoc (combineLocs $1 $2) $ text - "parse error in case statement: missing required 'of'" - } - | 'case' error {% parseErrorSDoc (getLoc $1) $ text - "parse error: naked case statement" - } optSemi :: { ([Located a],Bool) } : ';' { ([$1],True) } | {- empty -} { ([],False) } diff --git a/testsuite/tests/parser/should_fail/ParserNoLambdaCase.stderr b/testsuite/tests/parser/should_fail/ParserNoLambdaCase.stderr index 5a3f1cc080ff..147c8fef9cce 100644 --- a/testsuite/tests/parser/should_fail/ParserNoLambdaCase.stderr +++ b/testsuite/tests/parser/should_fail/ParserNoLambdaCase.stderr @@ -1,2 +1,2 @@ -ParserNoLambdaCase.hs:3:5: parse error: naked lambda expression '' +ParserNoLambdaCase.hs:3:6: parse error on input ‘case’ diff --git a/testsuite/tests/parser/should_fail/T10498a.hs b/testsuite/tests/parser/should_fail/T10498a.hs new file mode 100644 index 000000000000..5a9656f25454 --- /dev/null +++ b/testsuite/tests/parser/should_fail/T10498a.hs @@ -0,0 +1,14 @@ +{-# LANGUAGE LambdaCase #-} +module T10498a where + +-- ghc-7.10 would show the unhelpful error message: +-- +-- T10498a.hs:10:5: +-- parse error in if statement: missing required else clause + +foo = + if True + then + \case -> + 1 -> 2 + else id diff --git a/testsuite/tests/parser/should_fail/T10498a.stderr b/testsuite/tests/parser/should_fail/T10498a.stderr new file mode 100644 index 000000000000..ed98bc112035 --- /dev/null +++ b/testsuite/tests/parser/should_fail/T10498a.stderr @@ -0,0 +1,2 @@ + +T10498a.hs:12:15: parse error on input ‘->’ diff --git a/testsuite/tests/parser/should_fail/T10498b.hs b/testsuite/tests/parser/should_fail/T10498b.hs new file mode 100644 index 000000000000..19b62af5aafa --- /dev/null +++ b/testsuite/tests/parser/should_fail/T10498b.hs @@ -0,0 +1,7 @@ +module T10498b where + +-- ghc-7.10 would show the unhelpful error message: +-- +-- T10498b.hs:7:5: parse error in if statement: naked if statement + +f = if module then True else False diff --git a/testsuite/tests/parser/should_fail/T10498b.stderr b/testsuite/tests/parser/should_fail/T10498b.stderr new file mode 100644 index 000000000000..c1e26a115608 --- /dev/null +++ b/testsuite/tests/parser/should_fail/T10498b.stderr @@ -0,0 +1,2 @@ + +T10498b.hs:7:8: parse error on input ‘module’ diff --git a/testsuite/tests/parser/should_fail/all.T b/testsuite/tests/parser/should_fail/all.T index 26d576757a5a..5c99f5be7abf 100644 --- a/testsuite/tests/parser/should_fail/all.T +++ b/testsuite/tests/parser/should_fail/all.T @@ -89,3 +89,5 @@ test('T8506', normal, compile_fail, ['']) test('T10196Fail1', normal, compile_fail, ['']) test('T10196Fail2', normal, compile_fail, ['']) test('T10196Fail3', expect_broken(10196), compile_fail, ['']) +test('T10498a', normal, compile_fail, ['']) +test('T10498b', normal, compile_fail, ['']) diff --git a/testsuite/tests/parser/should_fail/readFail020.stderr b/testsuite/tests/parser/should_fail/readFail020.stderr index 0c00cdc79be2..0e3bde41da97 100644 --- a/testsuite/tests/parser/should_fail/readFail020.stderr +++ b/testsuite/tests/parser/should_fail/readFail020.stderr @@ -1,3 +1,2 @@ -readFail020.hs:3:5: - parse error in let binding: missing required 'in' +readFail020.hs:3:16: parse error on input ‘}’ -- GitLab