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:54:38 UTC

[groovy] branch GROOVY_3_0_X updated: 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_3_0_X
in repository https://gitbox.apache.org/repos/asf/groovy.git


The following commit(s) were added to refs/heads/GROOVY_3_0_X by this push:
     new c28da4b  GROOVY-10146: Groovy 3 compilation errors are less accurate than Groovy 2
c28da4b is described below

commit c28da4befa7059cfd192f074247712fd3bb4e299
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
    
    (cherry picked from commit 8ba70f6be91b87dec03561be323d733605ae1acd)
---
 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 9c44b31..b28a69e 100644
--- a/src/antlr/GroovyLexer.g4
+++ b/src/antlr/GroovyLexer.g4
@@ -966,5 +966,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/subprojects/parser-antlr4/src/test/groovy/org/apache/groovy/parser/antlr4/SyntaxErrorTest.groovy b/subprojects/parser-antlr4/src/test/groovy/org/apache/groovy/parser/antlr4/SyntaxErrorTest.groovy
index 4bbe12e..3b993f7 100644
--- a/subprojects/parser-antlr4/src/test/groovy/org/apache/groovy/parser/antlr4/SyntaxErrorTest.groovy
+++ b/subprojects/parser-antlr4/src/test/groovy/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')