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

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


The following commit(s) were added to refs/heads/GROOVY_4_0_X by this push:
     new db1d0b8c53 GROOVY-11764: do not visit super class field if it is 
package-private
db1d0b8c53 is described below

commit db1d0b8c53a755112c88b8909ed8cbbd7a7a2f38
Author: Eric Milles <[email protected]>
AuthorDate: Tue Nov 25 13:29:54 2025 -0600

    GROOVY-11764: do not visit super class field if it is package-private
---
 .../groovy/classgen/AsmClassGenerator.java         |  7 ++-
 src/test/groovy/bugs/Groovy11764.groovy            | 50 ++++++++++++++++++++++
 2 files changed, 55 insertions(+), 2 deletions(-)

diff --git a/src/main/java/org/codehaus/groovy/classgen/AsmClassGenerator.java 
b/src/main/java/org/codehaus/groovy/classgen/AsmClassGenerator.java
index 5aea4908e2..0c9b97f95b 100644
--- a/src/main/java/org/codehaus/groovy/classgen/AsmClassGenerator.java
+++ b/src/main/java/org/codehaus/groovy/classgen/AsmClassGenerator.java
@@ -151,6 +151,7 @@ import static 
org.codehaus.groovy.ast.tools.GeneralUtils.attrX;
 import static org.codehaus.groovy.ast.tools.GeneralUtils.callX;
 import static org.codehaus.groovy.ast.tools.GeneralUtils.classX;
 import static org.codehaus.groovy.ast.tools.GeneralUtils.fieldX;
+import static org.codehaus.groovy.ast.tools.GeneralUtils.inSamePackage;
 import static org.codehaus.groovy.ast.tools.GeneralUtils.isOrImplements;
 import static org.codehaus.groovy.ast.tools.GeneralUtils.maybeFallsThrough;
 import static org.codehaus.groovy.ast.tools.GeneralUtils.propX;
@@ -1219,8 +1220,10 @@ public class AsmClassGenerator extends ClassGenerator {
                     }
                 } else {
                     fieldNode = 
classNode.getSuperClass().getDeclaredField(name);
-                    // GROOVY-4497: do not visit super class field if it is 
private
-                    if (fieldNode != null && fieldNode.isPrivate()) fieldNode 
= null;
+                    // GROOVY-4497, GROOVY-11764: do not visit super class 
field if it is private or package-private
+                    if (fieldNode != null && (fieldNode.isPrivate() || 
!(fieldNode.isPublic() || fieldNode.isProtected() || inSamePackage(classNode, 
classNode.getSuperClass())))) {
+                        fieldNode = null;
+                    }
                 }
 
                 if (fieldNode != null) {
diff --git a/src/test/groovy/bugs/Groovy11764.groovy 
b/src/test/groovy/bugs/Groovy11764.groovy
new file mode 100644
index 0000000000..99e75314f4
--- /dev/null
+++ b/src/test/groovy/bugs/Groovy11764.groovy
@@ -0,0 +1,50 @@
+/*
+ *  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 bugs
+
+import org.junit.Test
+
+import static groovy.test.GroovyAssert.assertScript
+
+final class Groovy11764 {
+
+    @Test
+    void testReadFieldPropertyShadowing() {
+        def shell = new GroovyShell()
+        shell.parse '''package p
+            class A {
+                Number getValue() {
+                    42
+                }
+            }
+            class B extends A {
+                @groovy.transform.PackageScope String value = 'xx'
+            }
+        '''
+        assertScript shell, '''
+            class C extends p.B {
+                void test() {
+                    assert super.value == 42
+                }
+            }
+
+            new C().test()
+        '''
+    }
+}

Reply via email to