This is an automated email from the ASF dual-hosted git repository.
emilles pushed a commit to branch GROOVY_5_0_X
in repository https://gitbox.apache.org/repos/asf/groovy.git
The following commit(s) were added to refs/heads/GROOVY_5_0_X by this push:
new 78ca1a3c0f GROOVY-11827: pseudo-property via default-argument variant
78ca1a3c0f is described below
commit 78ca1a3c0fc134ad6b2a4bb22a7ff0fb75735546
Author: Eric Milles <[email protected]>
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'