You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@groovy.apache.org by pa...@apache.org on 2021/03/21 07:59:02 UTC

[groovy] branch master updated (445f8f3 -> ee359f9)

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

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


    from 445f8f3  GROOVY-8960: add test case
     new 279e290  GROOVY-7968: update test cases
     new ee359f9  GROOVY-7968: Fix class field and property with same name and both having init to throw compilation failure (closes #1500)

The 2 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 .../org/apache/groovy/parser/antlr4/AstBuilder.java    |  7 ++++++-
 .../scope/MultipleDefinitionOfSameVariableTest.groovy  | 18 ++++++++++++++++++
 2 files changed, 24 insertions(+), 1 deletion(-)

[groovy] 02/02: GROOVY-7968: Fix class field and property with same name and both having init to throw compilation failure (closes #1500)

Posted by pa...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

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

commit ee359f9362792ac0564b24332e67d234f00810c1
Author: Patrik Torn <pa...@vincit.fi>
AuthorDate: Wed Feb 24 13:44:45 2021 +0200

    GROOVY-7968: Fix class field and property with same name and both having init to throw compilation failure (closes #1500)
---
 src/main/java/org/apache/groovy/parser/antlr4/AstBuilder.java | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/src/main/java/org/apache/groovy/parser/antlr4/AstBuilder.java b/src/main/java/org/apache/groovy/parser/antlr4/AstBuilder.java
index e4051c1..244b420 100644
--- a/src/main/java/org/apache/groovy/parser/antlr4/AstBuilder.java
+++ b/src/main/java/org/apache/groovy/parser/antlr4/AstBuilder.java
@@ -1675,8 +1675,10 @@ public class AstBuilder extends GroovyParserBaseVisitor<Object> {
         FieldNode fieldNode = classNode.getDeclaredField(fieldName);
 
         if (fieldNode != null && !classNode.hasProperty(fieldName)) {
+            if (fieldNode.hasInitialExpression() && initialValue != null) {
+                throw createParsingFailedException("A field and a property have the same name '" + fieldName + "' and both have initial values", ctx);
+            }
             classNode.getFields().remove(fieldNode);
-
             propertyNode = new PropertyNode(fieldNode, modifiers | Opcodes.ACC_PUBLIC, null, null);
             classNode.addProperty(propertyNode);
         } else {
@@ -1718,6 +1720,9 @@ public class AstBuilder extends GroovyParserBaseVisitor<Object> {
         PropertyNode propertyNode = classNode.getProperty(fieldName);
 
         if (null != propertyNode && propertyNode.getField().isSynthetic()) {
+            if (propertyNode.hasInitialExpression() && initialValue != null) {
+                throw createParsingFailedException("A field and a property have the same name '" + fieldName + "' and both have initial values", ctx);
+            }
             classNode.getFields().remove(propertyNode.getField());
             fieldNode = new FieldNode(fieldName, modifiers, variableType, classNode.redirect(), initialValue);
             propertyNode.setField(fieldNode);

[groovy] 01/02: GROOVY-7968: update test cases

Posted by pa...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

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

commit 279e290c8c08bcf9682219b1bfae486730805ad8
Author: Joona <jo...@gmail.com>
AuthorDate: Sun Feb 14 12:42:58 2021 +0200

    GROOVY-7968: update test cases
---
 .../scope/MultipleDefinitionOfSameVariableTest.groovy  | 18 ++++++++++++++++++
 1 file changed, 18 insertions(+)

diff --git a/src/test/gls/scope/MultipleDefinitionOfSameVariableTest.groovy b/src/test/gls/scope/MultipleDefinitionOfSameVariableTest.groovy
index a113f13..146cd49 100644
--- a/src/test/gls/scope/MultipleDefinitionOfSameVariableTest.groovy
+++ b/src/test/gls/scope/MultipleDefinitionOfSameVariableTest.groovy
@@ -116,6 +116,15 @@ class MultipleDefinitionOfSameVariableTest extends CompilableTestSupport {
         """
     }
 
+    void testPropertyFieldBothInit() {
+        shouldNotCompile """
+            class A {
+                def foo = 3
+                private foo = 4
+            }
+        """
+    }
+
     void testFieldProperty() {
         shouldCompile """
             class A {
@@ -125,6 +134,15 @@ class MultipleDefinitionOfSameVariableTest extends CompilableTestSupport {
         """
     }
 
+    void testFieldPropertyBothInit() {
+        shouldNotCompile """
+            class A {
+                private foo = 'a'
+                def foo = 'b'
+            }
+        """
+    }
+
     void testFieldPropertyProperty() {
         shouldNotCompile """
             class A {