You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@groovy.apache.org by su...@apache.org on 2021/06/24 15:35:00 UTC
[groovy] 01/01: GROOVY-10146: Groovy 3 compilation errors are less
accurate than Groovy 2
This is an automated email from the ASF dual-hosted git repository.
sunlan pushed a commit to branch GROOVY-10146
in repository https://gitbox.apache.org/repos/asf/groovy.git
commit bcc8cacb40afd60b1c907d62276282e6d927e31c
Author: Daniel Sun <su...@apache.org>
AuthorDate: Thu Jun 24 23:34:49 2021 +0800
GROOVY-10146: Groovy 3 compilation errors are less accurate than Groovy 2
---
src/antlr/GroovyLexer.g4 | 2 +-
.../groovy/parser/antlr4/SyntaxErrorTest.groovy | 23 +++++++++++++++++++---
2 files changed, 21 insertions(+), 4 deletions(-)
diff --git a/src/antlr/GroovyLexer.g4 b/src/antlr/GroovyLexer.g4
index e74acac..5d8e883 100644
--- a/src/antlr/GroovyLexer.g4
+++ b/src/antlr/GroovyLexer.g4
@@ -977,5 +977,5 @@ SH_COMMENT
// Unexpected characters will be handled by groovy parser later.
UNEXPECTED_CHAR
- : .
+ : . { require(false, "Unexpected character: '" + getText().replace("'", "\\'") + "'", -1, false); }
;
diff --git a/src/test/org/apache/groovy/parser/antlr4/SyntaxErrorTest.groovy b/src/test/org/apache/groovy/parser/antlr4/SyntaxErrorTest.groovy
index 4bbe12e..3b993f7 100644
--- a/src/test/org/apache/groovy/parser/antlr4/SyntaxErrorTest.groovy
+++ b/src/test/org/apache/groovy/parser/antlr4/SyntaxErrorTest.groovy
@@ -83,7 +83,7 @@ final class SyntaxErrorTest extends GroovyTestCase {
// TODO: Could the character be escaped in the error message?
assert err == '''\
|startup failed:
- |test.groovy: 1: Unexpected input: 'def \u200B' @ line 1, column 5.
+ |test.groovy: 1: Unexpected character: '\u200B' @ line 1, column 5.
| def \u200Bname = null
| ^
|
@@ -99,7 +99,7 @@ final class SyntaxErrorTest extends GroovyTestCase {
// TODO: Could the character be escaped in the error message?
assert err == '''\
|startup failed:
- |test.groovy: 1: Unexpected input: '\u200B' @ line 1, column 7.
+ |test.groovy: 1: Unexpected character: '\u200B' @ line 1, column 7.
| def na\u200Bme = null
| ^
|
@@ -115,7 +115,7 @@ final class SyntaxErrorTest extends GroovyTestCase {
// TODO: Could the character be escaped in the error message?
assert err == '''\
|startup failed:
- |test.groovy: 1: Unexpected input: '\u000C' @ line 1, column 7.
+ |test.groovy: 1: Unexpected character: '\u000C' @ line 1, column 7.
| def na\u000Cme = null
| ^
|
@@ -123,6 +123,23 @@ final class SyntaxErrorTest extends GroovyTestCase {
|'''.stripMargin()
}
+ void 'test groovy core - UnexpectedCharacter 3'() {
+ def err = expectParseError '''\
+ |foo.bar {
+ | println 'Hello
+ |}
+ |'''.stripMargin()
+
+ assert err == '''\
+ |startup failed:
+ |test.groovy: 2: Unexpected character: '\\'' @ line 2, column 11.
+ | println 'Hello
+ | ^
+ |
+ |1 error
+ |'''.stripMargin()
+ }
+
void 'test groovy core - ParExpression'() {
TestUtils.doRunAndShouldFail('fail/ParExpression_01x.groovy')
TestUtils.doRunAndShouldFail('fail/ParExpression_02x.groovy')