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/26 16:19:47 UTC

[groovy] branch master updated: GROOVY-10150: Eliminate ambiguities while parsing non-static class creator

This is an automated email from the ASF dual-hosted git repository.

sunlan pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/groovy.git


The following commit(s) were added to refs/heads/master by this push:
     new 8c794fd  GROOVY-10150: Eliminate ambiguities while parsing non-static class creator
8c794fd is described below

commit 8c794fd54ac02002a5ca53a3da1490746d9c3a08
Author: Daniel Sun <su...@apache.org>
AuthorDate: Sun Jun 27 00:05:12 2021 +0800

    GROOVY-10150: Eliminate ambiguities while parsing non-static class creator
---
 src/antlr/GroovyParser.g4              | 6 +++---
 src/test/groovy/bugs/Groovy8947.groovy | 5 +++++
 2 files changed, 8 insertions(+), 3 deletions(-)

diff --git a/src/antlr/GroovyParser.g4 b/src/antlr/GroovyParser.g4
index f971d33..07f1fae 100644
--- a/src/antlr/GroovyParser.g4
+++ b/src/antlr/GroovyParser.g4
@@ -907,6 +907,9 @@ pathExpression returns [int t]
 pathElement returns [int t]
     :   nls
         (
+            DOT nls NEW creator[1]
+            { $t = 6; }
+        |
             // AT: foo.@bar selects the field (or attribute), not property
             (
                 (   DOT                 // The all-powerful dot.
@@ -921,9 +924,6 @@ pathElement returns [int t]
             )
             namePart
             { $t = 1; }
-        |
-            DOT nls NEW creator[1]
-            { $t = 6; }
 
             // Can always append a block, as foo{bar}
         |   closureOrLambdaExpression
diff --git a/src/test/groovy/bugs/Groovy8947.groovy b/src/test/groovy/bugs/Groovy8947.groovy
index d7f8c6c..f11e565 100644
--- a/src/test/groovy/bugs/Groovy8947.groovy
+++ b/src/test/groovy/bugs/Groovy8947.groovy
@@ -45,6 +45,11 @@ final class Groovy8947 {
             assert 4 == new Computer().new Cpu(4).coreNumber
             assert 4 == Computer.newCpuInstance(4).coreNumber
             assert 0 == new HashSet(new ArrayList()).size()
+            
+            def coreNumber = new Computer().new Cpu(4).coreNumber
+            assert 4 == coreNumber
+            def cpu = new Computer().new Cpu(4)
+            assert 4 == cpu.coreNumber
         '''
     }