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 2020/07/01 16:15:08 UTC

[groovy] branch GROOVY_3_0_X updated (87da0a5 -> 9b0e2f4)

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

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


    from 87da0a5  Tweak `methodDeclaration` rule
     new bd100e3  GROOVY-9611: Reflexive access to class attributes broken in Groovy 3
     new 9b0e2f4  GROOVY-9611: Reflexive access to class attributes broken in Groovy 3 (port for 3_0_X)

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:
 .../codehaus/groovy/antlr/AntlrParserPlugin.java    |  2 +-
 .../bugs/{Groovy9153.groovy => Groovy9611.groovy}   | 21 +++++++++++----------
 .../org/apache/groovy/parser/antlr4/AstBuilder.java |  2 +-
 3 files changed, 13 insertions(+), 12 deletions(-)
 copy src/test/groovy/bugs/{Groovy9153.groovy => Groovy9611.groovy} (70%)


[groovy] 02/02: GROOVY-9611: Reflexive access to class attributes broken in Groovy 3 (port for 3_0_X)

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

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

commit 9b0e2f46f67b190125753c36b6cd1157d3e56b8d
Author: Paul King <pa...@asert.com.au>
AuthorDate: Thu Jul 2 02:12:08 2020 +1000

    GROOVY-9611: Reflexive access to class attributes broken in Groovy 3 (port for 3_0_X)
---
 src/main/java/org/codehaus/groovy/antlr/AntlrParserPlugin.java | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/src/main/java/org/codehaus/groovy/antlr/AntlrParserPlugin.java b/src/main/java/org/codehaus/groovy/antlr/AntlrParserPlugin.java
index 7fcabac..855675b 100644
--- a/src/main/java/org/codehaus/groovy/antlr/AntlrParserPlugin.java
+++ b/src/main/java/org/codehaus/groovy/antlr/AntlrParserPlugin.java
@@ -611,7 +611,7 @@ public class AntlrParserPlugin extends ASTHelper implements ParserPlugin, Groovy
         if (enumConstantBeingDef) {
             classNode = new EnumConstantClassNode(outerClass, innerClassName, Opcodes.ACC_PUBLIC, ClassHelper.OBJECT_TYPE);
         } else {
-            classNode = new InnerClassNode(outerClass, innerClassName, 0, ClassHelper.OBJECT_TYPE);
+            classNode = new InnerClassNode(outerClass, innerClassName, Opcodes.ACC_PUBLIC, ClassHelper.OBJECT_TYPE);
         }
         ((InnerClassNode) classNode).setAnonymous(true);
         classNode.setEnclosingMethod(methodNode);


[groovy] 01/02: GROOVY-9611: Reflexive access to class attributes broken in Groovy 3

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

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

commit bd100e3895e984426b1f5c4690fd7afe8b65f5a7
Author: Paul King <pa...@asert.com.au>
AuthorDate: Thu Jul 2 00:51:44 2020 +1000

    GROOVY-9611: Reflexive access to class attributes broken in Groovy 3
---
 src/test/groovy/bugs/Groovy9611.groovy             | 41 ++++++++++++++++++++++
 .../apache/groovy/parser/antlr4/AstBuilder.java    |  2 +-
 2 files changed, 42 insertions(+), 1 deletion(-)

diff --git a/src/test/groovy/bugs/Groovy9611.groovy b/src/test/groovy/bugs/Groovy9611.groovy
new file mode 100644
index 0000000..ba20083
--- /dev/null
+++ b/src/test/groovy/bugs/Groovy9611.groovy
@@ -0,0 +1,41 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you under the Apache License, Version 2.0 (the
+ *  "License"); you may not use this file except in compliance
+ *  with the License.  You may obtain a copy of the License at
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing,
+ *  software distributed under the License is distributed on an
+ *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *  KIND, either express or implied.  See the License for the
+ *  specific language governing permissions and limitations
+ *  under the License.
+ */
+package groovy.bugs
+
+import org.junit.Test
+
+import static groovy.test.GroovyAssert.assertScript
+
+final class Groovy9611 {
+    @Test
+    void testAccessFieldWithinAICUsingReflection() {
+        assertScript '''
+            import java.lang.reflect.Field
+            class C {
+              int method() {
+                for (Field f : getClass().fields)
+                  if (f.name == 'i') return f.get(this)
+                return -1
+              }
+            }
+            def c = new C() { public int i = 42 }
+            assert c.method() == 42
+        '''
+    }
+}
diff --git a/subprojects/parser-antlr4/src/main/java/org/apache/groovy/parser/antlr4/AstBuilder.java b/subprojects/parser-antlr4/src/main/java/org/apache/groovy/parser/antlr4/AstBuilder.java
index 6b69578..d138716 100644
--- a/subprojects/parser-antlr4/src/main/java/org/apache/groovy/parser/antlr4/AstBuilder.java
+++ b/subprojects/parser-antlr4/src/main/java/org/apache/groovy/parser/antlr4/AstBuilder.java
@@ -3240,7 +3240,7 @@ public class AstBuilder extends GroovyParserBaseVisitor<Object> {
             // and remove the final modifier from classNode to allow the sub class
             superClass.setModifiers(superClass.getModifiers() & ~Opcodes.ACC_FINAL);
         } else { // anonymous inner class
-            anonymousInnerClass = new InnerClassNode(outerClass, innerClassName, 0, superClass);
+            anonymousInnerClass = new InnerClassNode(outerClass, innerClassName, Opcodes.ACC_PUBLIC, superClass);
         }
 
         anonymousInnerClass.setUsingGenerics(false);