You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@groovy.apache.org by em...@apache.org on 2025/12/30 17:29:51 UTC

(groovy) branch master updated: GROOVY-11827: pseudo-property via default-argument variant

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

emilles 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 41ab97c786 GROOVY-11827: pseudo-property via default-argument variant
41ab97c786 is described below

commit 41ab97c78682717f14987fe572cd1d116e4a1363
Author: Eric Milles <er...@thomsonreuters.com>
AuthorDate: Tue Dec 30 11:06:04 2025 -0600

    GROOVY-11827: pseudo-property via default-argument variant
---
 .../codehaus/groovy/classgen/VariableScopeVisitor.java   |  3 ++-
 src/test/groovy/bugs/Groovy5364.groovy                   | 16 ++++++++++++++++
 2 files changed, 18 insertions(+), 1 deletion(-)

diff --git a/src/main/java/org/codehaus/groovy/classgen/VariableScopeVisitor.java b/src/main/java/org/codehaus/groovy/classgen/VariableScopeVisitor.java
index e615e6909b..de8445a686 100644
--- a/src/main/java/org/codehaus/groovy/classgen/VariableScopeVisitor.java
+++ b/src/main/java/org/codehaus/groovy/classgen/VariableScopeVisitor.java
@@ -73,6 +73,7 @@ import java.util.function.Supplier;
 import static java.lang.reflect.Modifier.isFinal;
 import static java.lang.reflect.Modifier.isStatic;
 import static org.apache.groovy.ast.tools.MethodNodeUtils.getPropertyName;
+import static org.apache.groovy.ast.tools.MethodNodeUtils.withDefaultArgumentMethods;
 import static org.codehaus.groovy.ast.tools.GeneralUtils.getAllProperties;
 
 /**
@@ -203,7 +204,7 @@ public class VariableScopeVisitor extends ClassCodeVisitorSupport {
                 if (name.equals(pn.getName())) return pn;
             }
 
-            for (MethodNode mn : cn.getMethods()) {
+            for (MethodNode mn : withDefaultArgumentMethods(cn.getMethods())) { // GROOVY-11827
                 if ((abstractType || !mn.isAbstract()) && name.equals(getPropertyName(mn))) {
                     // check for super property before returning a pseudo-property
                     for (PropertyNode pn : getAllProperties(cn.getSuperClass())) {
diff --git a/src/test/groovy/bugs/Groovy5364.groovy b/src/test/groovy/bugs/Groovy5364.groovy
index 2655e08200..3abaeb5290 100644
--- a/src/test/groovy/bugs/Groovy5364.groovy
+++ b/src/test/groovy/bugs/Groovy5364.groovy
@@ -88,8 +88,24 @@ final class Groovy5364 {
         '''
     }
 
+    // GROOVY-11827
     @Test
     void testStaticScriptMethodAsProperty6() {
+        assertScript '''
+            static getStaticProperty(o=null) {
+                'x'
+            }
+
+            static void test() {
+                assert 'x' == getStaticProperty()
+                assert 'x' == staticProperty // Apparent variable 'staticProperty' was found in a static scope but doesn't refer to a local variable, static field or class
+            }
+            test()
+        '''
+    }
+
+    @Test
+    void testStaticScriptMethodAsProperty7() {
         def err = shouldFail '''
             def getNonStaticProperty() {
                 'x'