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 2026/02/24 18:01:11 UTC
(groovy) 02/02: `VariableScopeVisitor#findClassMember`: collect traits in reverse order
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
commit f5666584e120e2cc5e0289bd28ab594632604d09
Author: Eric Milles <er...@thomsonreuters.com>
AuthorDate: Tue Feb 24 11:39:26 2026 -0600
`VariableScopeVisitor#findClassMember`: collect traits in reverse order
---
.../codehaus/groovy/classgen/VariableScopeVisitor.java | 16 ++++++++++++----
1 file changed, 12 insertions(+), 4 deletions(-)
diff --git a/src/main/java/org/codehaus/groovy/classgen/VariableScopeVisitor.java b/src/main/java/org/codehaus/groovy/classgen/VariableScopeVisitor.java
index 4a9307a4db..820a6499a6 100644
--- a/src/main/java/org/codehaus/groovy/classgen/VariableScopeVisitor.java
+++ b/src/main/java/org/codehaus/groovy/classgen/VariableScopeVisitor.java
@@ -73,10 +73,10 @@ import java.util.function.Consumer;
import java.util.function.Supplier;
import static java.lang.reflect.Modifier.isStatic;
-import static java.util.Collections.addAll;
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;
+import static org.codehaus.groovy.transform.trait.Traits.isTrait;
/**
* Initializes the variable scopes for an AST.
@@ -197,6 +197,14 @@ public class VariableScopeVisitor extends ClassCodeVisitorSupport {
private Variable findClassMember(final ClassNode node, final String name) {
final boolean abstractType = node.isAbstract();
Deque<ClassNode> interfaces = new LinkedList<>();
+ Consumer<ClassNode[]> interfacesAndTraits = (next) -> {
+ for (int i = 0; i < next.length; i += 1) {
+ if (!isTrait(next[i])) interfaces.add(next[i]);
+ }
+ for (int i = next.length - 1; i >= 0; i -= 1) {
+ if ( isTrait(next[i])) interfaces.add(next[i]);
+ }
+ };
for (ClassNode cn = node; cn != null && !ClassHelper.isObjectType(cn); cn = cn.getSuperClass()) {
for (FieldNode fn : cn.getFields()) {
@@ -232,7 +240,7 @@ public class VariableScopeVisitor extends ClassCodeVisitorSupport {
}
}
- addAll(interfaces, cn.getInterfaces());
+ interfacesAndTraits.accept(cn.getInterfaces());
}
Set<ClassNode> done = new HashSet<>();
@@ -240,7 +248,7 @@ public class VariableScopeVisitor extends ClassCodeVisitorSupport {
ClassNode i = interfaces.remove();
if (done.add(i)) {
FieldNode fn = i.getDeclaredField(name);
- if (fn != null) {
+ if (fn != null && !isTrait(i)) {
return fn;
}
PropertyNode pn = i.getProperty(name);
@@ -248,7 +256,7 @@ public class VariableScopeVisitor extends ClassCodeVisitorSupport {
return pn;
}
- addAll(interfaces, i.getInterfaces());
+ interfacesAndTraits.accept(i.getInterfaces());
}
}