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

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

commit f3e3bffa427b293e489397f65c70b145e6023f31
Author: Paul King <[email protected]>
AuthorDate: Fri Jul 10 19:17:59 2026 +1000

    GROOVY-12143: use the fluent AstQuery API for the nested-function check
    
    Address review feedback: containsNestedFunction hand-rolled a 
CodeVisitorSupport
    with a boolean[] escape flag; replace it with the read-only fluent query 
added in
    GROOVY-12116, matching the HasRecursiveCalls idiom:
    
        AstQuery.from(code).descendants(ClosureExpression.class).any()
    
    LambdaExpression extends ClosureExpression, so the single descendants() type
    covers both nested closures and lambdas. Behaviour is unchanged (a lambda 
whose
    body nests a closure still declines the hoist). The two remaining local 
visitors
    are intentionally left: rebindCapturedFieldsToValueParams mutates the AST 
(the
    query API is read-only) and writesAnyCapture's three-node-type predicate 
would be
    a lateral move, not a simplification.
---
 .../groovy/classgen/asm/sc/StaticTypesLambdaWriter.java        | 10 +++-------
 1 file changed, 3 insertions(+), 7 deletions(-)

diff --git 
a/src/main/java/org/codehaus/groovy/classgen/asm/sc/StaticTypesLambdaWriter.java
 
b/src/main/java/org/codehaus/groovy/classgen/asm/sc/StaticTypesLambdaWriter.java
index 1c2d643053..35ae0e8a7a 100644
--- 
a/src/main/java/org/codehaus/groovy/classgen/asm/sc/StaticTypesLambdaWriter.java
+++ 
b/src/main/java/org/codehaus/groovy/classgen/asm/sc/StaticTypesLambdaWriter.java
@@ -35,6 +35,7 @@ import org.codehaus.groovy.ast.expr.LambdaExpression;
 import org.codehaus.groovy.ast.expr.PostfixExpression;
 import org.codehaus.groovy.ast.expr.PrefixExpression;
 import org.codehaus.groovy.ast.expr.VariableExpression;
+import org.codehaus.groovy.ast.query.AstQuery;
 import org.codehaus.groovy.ast.stmt.Statement;
 import org.codehaus.groovy.syntax.Types;
 import org.codehaus.groovy.classgen.BytecodeInstruction;
@@ -439,13 +440,8 @@ public class StaticTypesLambdaWriter extends LambdaWriter 
implements AbstractFun
     }
 
     private static boolean containsNestedFunction(final Statement code) {
-        if (code == null) return false;
-        boolean[] found = {false};
-        code.visit(new CodeVisitorSupport() {
-            @Override public void visitClosureExpression(final 
ClosureExpression e) { found[0] = true; }
-            @Override public void visitLambdaExpression(final LambdaExpression 
e) { found[0] = true; }
-        });
-        return found[0];
+        // LambdaExpression extends ClosureExpression, so this matches both 
nested closures and lambdas.
+        return code != null && 
AstQuery.from(code).descendants(ClosureExpression.class).any();
     }
 
     /**

Reply via email to