You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@groovy.apache.org by su...@apache.org on 2019/12/12 02:33:06 UTC

[groovy] branch GROOVY_3_0_X updated (d977394 -> f4331c6)

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

sunlan pushed a change to branch GROOVY_3_0_X
in repository https://gitbox.apache.org/repos/asf/groovy.git.


    from d977394  Get system property safely
     new 8996c8f  GROOVY-8762, GROOVY-9332, GROOVY-9333: isInClosure() again for lambdas
     new ac76e6f  minor edits
     new 4d57172  fix class config for wildcard types
     new fae3798  Minor refactoring: remove redundant code
     new f5c0012  Minor refactoring: remove redundant internal variable of lambda
     new f4331c6  GROOVY-9328: add outer class accessors to all outer classes

The 6 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 .../groovy/classgen/asm/WriterController.java      |    2 +-
 .../classgen/asm/sc/StaticTypesLambdaWriter.java   |   54 +-
 .../transform/sc/StaticCompilationVisitor.java     |   33 +-
 .../org/codehaus/groovy/vmplugin/v5/Java5.java     |   24 +-
 src/test/groovy/transform/stc/LambdaTest.groovy    | 2513 +++++++++++---------
 .../asm/sc/MixedModeStaticCompilationTest.groovy   |   45 +-
 .../apache/groovy/parser/antlr4/AstBuilder.java    |   22 +-
 7 files changed, 1435 insertions(+), 1258 deletions(-)


[groovy] 02/06: minor edits

Posted by su...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

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

commit ac76e6ff719d51d7dac9494bb76f51ce66f6ea8c
Author: Eric Milles <er...@thomsonreuters.com>
AuthorDate: Wed Dec 11 11:56:01 2019 -0600

    minor edits
    
    (cherry picked from commit 6606034804da332e56c42dc5d39a94a4cf400cfe)
---
 .../apache/groovy/parser/antlr4/AstBuilder.java    | 22 ++++++----------------
 1 file changed, 6 insertions(+), 16 deletions(-)

diff --git a/subprojects/parser-antlr4/src/main/java/org/apache/groovy/parser/antlr4/AstBuilder.java b/subprojects/parser-antlr4/src/main/java/org/apache/groovy/parser/antlr4/AstBuilder.java
index 83afe21..6987fa6 100644
--- a/subprojects/parser-antlr4/src/main/java/org/apache/groovy/parser/antlr4/AstBuilder.java
+++ b/subprojects/parser-antlr4/src/main/java/org/apache/groovy/parser/antlr4/AstBuilder.java
@@ -3534,26 +3534,16 @@ public class AstBuilder extends GroovyParserBaseVisitor<Object> implements Groov
     }
 
     @Override
-    public Parameter[] visitStandardLambdaParameters(StandardLambdaParametersContext ctx) {
+    public Parameter[] visitStandardLambdaParameters(final StandardLambdaParametersContext ctx) {
         if (asBoolean(ctx.variableDeclaratorId())) {
-            return new Parameter[]{
-                    configureAST(
-                            new Parameter(
-                                    ClassHelper.OBJECT_TYPE,
-                                    this.visitVariableDeclaratorId(ctx.variableDeclaratorId()).getName()
-                            ),
-                            ctx.variableDeclaratorId()
-                    )
-            };
+            VariableExpression variable = this.visitVariableDeclaratorId(ctx.variableDeclaratorId());
+            Parameter parameter = new Parameter(ClassHelper.OBJECT_TYPE, variable.getName());
+            configureAST(parameter, variable);
+            return new Parameter[]{parameter};
         }
 
         Parameter[] parameters = this.visitFormalParameters(ctx.formalParameters());
-
-        if (0 == parameters.length) {
-            return null;
-        }
-
-        return parameters;
+        return (parameters.length > 0 ? parameters : null);
     }
 
     @Override


[groovy] 04/06: Minor refactoring: remove redundant code

Posted by su...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

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

commit fae37984f50474719281f59b1a0d3a964645aa76
Author: Daniel.Sun <re...@hotmail.com>
AuthorDate: Thu Dec 12 08:10:01 2019 +0800

    Minor refactoring: remove redundant code
    
    (cherry picked from commit 1a5d2803107911adb1cdbcd02c5826d4414f38eb)
---
 .../classgen/asm/sc/StaticTypesLambdaWriter.java   | 42 ++--------------------
 1 file changed, 3 insertions(+), 39 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 8f2fe0c..88da6c7 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
@@ -34,7 +34,6 @@ import org.codehaus.groovy.ast.expr.ClosureExpression;
 import org.codehaus.groovy.ast.expr.ConstantExpression;
 import org.codehaus.groovy.ast.expr.Expression;
 import org.codehaus.groovy.ast.expr.LambdaExpression;
-import org.codehaus.groovy.ast.expr.MethodCallExpression;
 import org.codehaus.groovy.ast.expr.VariableExpression;
 import org.codehaus.groovy.ast.stmt.BlockStatement;
 import org.codehaus.groovy.ast.stmt.Statement;
@@ -186,18 +185,6 @@ public class StaticTypesLambdaWriter extends LambdaWriter implements AbstractFun
             }
 
             @Override
-            public void visitMethodCallExpression(MethodCallExpression call) {
-                if (!call.getMethodTarget().isStatic()) {
-                    Expression objectExpression = call.getObjectExpression();
-                    if (objectExpression instanceof VariableExpression && ENCLOSING_THIS.equals(((VariableExpression) objectExpression).getName())) {
-                        objectHolder.setObject(true);
-                    }
-                }
-
-                super.visitMethodCallExpression(call);
-            }
-
-            @Override
             protected SourceUnit getSourceUnit() {
                 return null;
             }
@@ -300,8 +287,7 @@ public class StaticTypesLambdaWriter extends LambdaWriter implements AbstractFun
         ConstructorNode constructorNode = addConstructor(expression, localVariableParameters, answer, createBlockStatementForConstructor(expression, outerClass, classNode));
         constructorNode.putNodeMetaData(IS_GENERATED_CONSTRUCTOR, Boolean.TRUE);
 
-        Parameter enclosingThisParameter = syntheticLambdaMethodNode.getParameters()[0];
-        new TransformationVisitor(answer, enclosingThisParameter).visitMethod(syntheticLambdaMethodNode);
+        new LambdaBodyTransformationVisitor(answer).visitMethod(syntheticLambdaMethodNode);
 
         return answer;
     }
@@ -443,13 +429,11 @@ public class StaticTypesLambdaWriter extends LambdaWriter implements AbstractFun
         return staticTypesClosureWriter.createClosureClass(expression, mods);
     }
 
-    private static final class TransformationVisitor extends ClassCodeVisitorSupport {
+    private static final class LambdaBodyTransformationVisitor extends ClassCodeVisitorSupport {
         private final CorrectAccessedVariableVisitor correctAccessedVariableVisitor;
-        private final Parameter enclosingThisParameter;
 
-        public TransformationVisitor(InnerClassNode icn, Parameter enclosingThisParameter) {
+        public LambdaBodyTransformationVisitor(InnerClassNode icn) {
             this.correctAccessedVariableVisitor = new CorrectAccessedVariableVisitor(icn);
-            this.enclosingThisParameter = enclosingThisParameter;
         }
 
         @Override
@@ -458,26 +442,6 @@ public class StaticTypesLambdaWriter extends LambdaWriter implements AbstractFun
         }
 
         @Override
-        public void visitMethodCallExpression(MethodCallExpression call) {
-            if (!call.getMethodTarget().isStatic()) {
-                Expression objectExpression = call.getObjectExpression();
-
-                if (objectExpression instanceof VariableExpression) {
-                    VariableExpression originalObjectExpression = (VariableExpression) objectExpression;
-                    if (null == originalObjectExpression.getAccessedVariable()) {
-                        VariableExpression thisVariable = new VariableExpression(enclosingThisParameter);
-                        thisVariable.setSourcePosition(originalObjectExpression);
-
-                        call.setObjectExpression(thisVariable);
-                        call.setImplicitThis(false);
-                    }
-                }
-            }
-
-            super.visitMethodCallExpression(call);
-        }
-
-        @Override
         protected SourceUnit getSourceUnit() {
             return null;
         }


[groovy] 03/06: fix class config for wildcard types

Posted by su...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

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

commit 4d571723ef77920a35cc540ab943333cf2caa380
Author: Eric Milles <er...@thomsonreuters.com>
AuthorDate: Wed Dec 11 14:39:11 2019 -0600

    fix class config for wildcard types
    
    beware of [Object] for upper bounds; often it's <? super T> or just <?>
    
    (cherry picked from commit 1e3dfbc0414a38f3214ee061ad63cfab40da2003)
---
 .../org/codehaus/groovy/vmplugin/v5/Java5.java     | 24 +++++++++++-----------
 1 file changed, 12 insertions(+), 12 deletions(-)

diff --git a/src/main/java/org/codehaus/groovy/vmplugin/v5/Java5.java b/src/main/java/org/codehaus/groovy/vmplugin/v5/Java5.java
index db0fc3f..f3e9aab 100644
--- a/src/main/java/org/codehaus/groovy/vmplugin/v5/Java5.java
+++ b/src/main/java/org/codehaus/groovy/vmplugin/v5/Java5.java
@@ -150,23 +150,23 @@ public class Java5 implements VMPlugin {
         return node.makeArray();
     }
 
-    private ClassNode configureWildcardType(WildcardType wildcardType) {
+    private ClassNode configureWildcardType(final WildcardType wildcardType) {
         ClassNode base = ClassHelper.makeWithoutCaching("?");
         base.setRedirect(ClassHelper.OBJECT_TYPE);
-        //TODO: more than one lower bound for wildcards?
-        ClassNode[] lowers = configureTypes(wildcardType.getLowerBounds());
-        ClassNode lower = null;
-        // TODO: is it safe to remove this? What was the original intention?
-        if (lowers != null) lower = lowers[0];
 
-        ClassNode[] upper = configureTypes(wildcardType.getUpperBounds());
-        GenericsType t = new GenericsType(base, upper, lower);
-        t.setWildcard(true);
+        ClassNode[] lowers = configureTypes(wildcardType.getLowerBounds());
+        ClassNode[] uppers = configureTypes(wildcardType.getUpperBounds());
+        // beware of [Object] upper bounds; often it's <?> or <? super T>
+        if (lowers != null || wildcardType.getTypeName().equals("?")) {
+            uppers = null;
+        }
 
-        ClassNode ref = ClassHelper.makeWithoutCaching(Object.class, false);
-        ref.setGenericsTypes(new GenericsType[]{t});
+        GenericsType gt = new GenericsType(base, uppers, lowers != null ? lowers[0] : null);
+        gt.setWildcard(true);
 
-        return ref;
+        ClassNode wt = ClassHelper.makeWithoutCaching(Object.class, false);
+        wt.setGenericsTypes(new GenericsType[]{gt});
+        return wt;
     }
 
     private ClassNode configureParameterizedType(ParameterizedType parameterizedType) {


[groovy] 05/06: Minor refactoring: remove redundant internal variable of lambda

Posted by su...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

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

commit f5c001232d008d1022a6fb176699e47902dc533e
Author: Daniel.Sun <re...@hotmail.com>
AuthorDate: Thu Dec 12 08:18:35 2019 +0800

    Minor refactoring: remove redundant internal variable of lambda
    
    (cherry picked from commit ca5739716baa19c6475df0d6bb31c523c8124f44)
---
 .../groovy/classgen/asm/sc/StaticTypesLambdaWriter.java      | 12 +-----------
 1 file changed, 1 insertion(+), 11 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 88da6c7..05dae39 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
@@ -72,7 +72,6 @@ import static org.objectweb.asm.Opcodes.CHECKCAST;
 import static org.objectweb.asm.Opcodes.DUP;
 import static org.objectweb.asm.Opcodes.H_INVOKEVIRTUAL;
 import static org.objectweb.asm.Opcodes.ICONST_0;
-import static org.objectweb.asm.Opcodes.ICONST_1;
 import static org.objectweb.asm.Opcodes.INVOKESPECIAL;
 import static org.objectweb.asm.Opcodes.INVOKEVIRTUAL;
 import static org.objectweb.asm.Opcodes.NEW;
@@ -83,7 +82,6 @@ import static org.objectweb.asm.Opcodes.NEW;
 public class StaticTypesLambdaWriter extends LambdaWriter implements AbstractFunctionalInterfaceWriter {
     private static final String DO_CALL = "doCall";
     private static final String LAMBDA_SHARED_VARIABLES = "__LAMBDA_SHARED_VARIABLES";
-    private static final String ENCLOSING_THIS = "__enclosing_this";
     private static final String LAMBDA_THIS = "__lambda_this";
     private static final String INIT = "<init>";
     private static final String IS_GENERATED_CONSTRUCTOR = "__IS_GENERATED_CONSTRUCTOR";
@@ -137,7 +135,6 @@ public class StaticTypesLambdaWriter extends LambdaWriter implements AbstractFun
 
             boolean accessingInstanceMembers = isAccessingInstanceMembersOfEnclosingClass(syntheticLambdaMethodNode);
             newGroovyLambdaWrapperAndLoad(lambdaWrapperClassNode, expression, accessingInstanceMembers);
-            loadEnclosingClassInstance(accessingInstanceMembers);
         }
 
         MethodVisitor mv = controller.getMethodVisitor();
@@ -154,7 +151,7 @@ public class StaticTypesLambdaWriter extends LambdaWriter implements AbstractFun
             mv.visitTypeInsn(CHECKCAST, "java/io/Serializable");
         }
 
-        operandStack.replace(redirect, 2);
+        operandStack.replace(redirect, 1);
     }
 
     private Parameter[] createDeserializeLambdaMethodParams() {
@@ -238,7 +235,6 @@ public class StaticTypesLambdaWriter extends LambdaWriter implements AbstractFun
     private String createAbstractMethodDesc(ClassNode functionalInterfaceType, ClassNode lambdaClassNode) {
         List<Parameter> lambdaSharedVariableList = new LinkedList<>();
 
-        prependEnclosingThis(lambdaSharedVariableList);
         prependParameter(lambdaSharedVariableList, LAMBDA_THIS, lambdaClassNode);
 
         return BytecodeHelper.getMethodDescriptor(functionalInterfaceType.redirect(), lambdaSharedVariableList.toArray(Parameter.EMPTY_ARRAY));
@@ -312,7 +308,6 @@ public class StaticTypesLambdaWriter extends LambdaWriter implements AbstractFun
         removeInitialValues(localVariableParameters);
 
         List<Parameter> methodParameterList = new LinkedList<>(Arrays.asList(parametersWithExactType));
-        prependEnclosingThis(methodParameterList);
 
         MethodNode methodNode =
                 answer.addMethod(
@@ -330,10 +325,6 @@ public class StaticTypesLambdaWriter extends LambdaWriter implements AbstractFun
         return methodNode;
     }
 
-    private Parameter prependEnclosingThis(List<Parameter> methodParameterList) {
-        return prependParameter(methodParameterList, ENCLOSING_THIS, controller.getClassNode().getPlainNodeReference());
-    }
-
     private Parameter[] createParametersWithExactType(LambdaExpression expression) {
         Parameter[] parameters = expression.getParameters();
         if (parameters == null) {
@@ -390,7 +381,6 @@ public class StaticTypesLambdaWriter extends LambdaWriter implements AbstractFun
                     @Override
                     public void visit(MethodVisitor mv) {
                         callGetCapturedArg(mv, ICONST_0, lambdaWrapperClassNode);
-                        callGetCapturedArg(mv, ICONST_1, classNode);
                     }
 
                     private void callGetCapturedArg(MethodVisitor mv, int capturedArgIndex, ClassNode resultType) {


[groovy] 06/06: GROOVY-9328: add outer class accessors to all outer classes

Posted by su...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

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

commit f4331c6b7cad7ebb9437ebd99f22906519ad8515
Author: Eric Milles <er...@thomsonreuters.com>
AuthorDate: Tue Dec 10 12:06:42 2019 -0600

    GROOVY-9328: add outer class accessors to all outer classes
    
    (cherry picked from commit 2c06560a7bd7d8d716867e43e92e7a7eb9fa5e90)
---
 .../transform/sc/StaticCompilationVisitor.java     | 33 ++++++++++------
 .../asm/sc/MixedModeStaticCompilationTest.groovy   | 45 ++++++++++++++++++----
 2 files changed, 58 insertions(+), 20 deletions(-)

diff --git a/src/main/java/org/codehaus/groovy/transform/sc/StaticCompilationVisitor.java b/src/main/java/org/codehaus/groovy/transform/sc/StaticCompilationVisitor.java
index a331a58..99b72c1 100644
--- a/src/main/java/org/codehaus/groovy/transform/sc/StaticCompilationVisitor.java
+++ b/src/main/java/org/codehaus/groovy/transform/sc/StaticCompilationVisitor.java
@@ -56,7 +56,6 @@ import org.codehaus.groovy.classgen.asm.TypeChooser;
 import org.codehaus.groovy.classgen.asm.WriterControllerFactory;
 import org.codehaus.groovy.classgen.asm.sc.StaticCompilationMopWriter;
 import org.codehaus.groovy.classgen.asm.sc.StaticTypesTypeChooser;
-import org.codehaus.groovy.control.CompilationFailedException;
 import org.codehaus.groovy.control.CompilationUnit;
 import org.codehaus.groovy.control.SourceUnit;
 import org.codehaus.groovy.transform.stc.StaticTypeCheckingSupport;
@@ -154,16 +153,20 @@ public class StaticCompilationVisitor extends StaticTypeCheckingVisitor {
     }
 
     private void addDynamicOuterClassAccessorsCallback(final ClassNode outer) {
-        if (outer != null && !isStaticallyCompiled(outer) && outer.getNodeMetaData(DYNAMIC_OUTER_NODE_CALLBACK) == null) {
-            outer.putNodeMetaData(DYNAMIC_OUTER_NODE_CALLBACK, new CompilationUnit.PrimaryClassNodeOperation() {
-                @Override
-                public void call(SourceUnit source, GeneratorContext context, ClassNode classNode) throws CompilationFailedException {
-                    if (classNode == outer) {
-                        addPrivateBridgeMethods(classNode);
-                        addPrivateFieldsAccessors(classNode);
+        if (outer != null) {
+            if (!isStaticallyCompiled(outer) && outer.getNodeMetaData(DYNAMIC_OUTER_NODE_CALLBACK) == null) {
+                outer.putNodeMetaData(DYNAMIC_OUTER_NODE_CALLBACK, new CompilationUnit.PrimaryClassNodeOperation() {
+                    @Override
+                    public void call(final SourceUnit source, final GeneratorContext context, final ClassNode classNode) {
+                        if (classNode == outer) {
+                            addPrivateBridgeMethods(classNode);
+                            addPrivateFieldsAccessors(classNode);
+                        }
                     }
-                }
-            });
+                });
+            }
+            // GROOVY-9328: apply to outer classes
+            addDynamicOuterClassAccessorsCallback(outer.getOuterClass());
         }
     }
 
@@ -187,7 +190,10 @@ public class StaticCompilationVisitor extends StaticTypeCheckingVisitor {
         }
         super.visitClass(node);
         addPrivateFieldAndMethodAccessors(node);
-        if (isStaticallyCompiled(node)) addDynamicOuterClassAccessorsCallback(node.getOuterClass());
+        if (isStaticallyCompiled(node)) {
+            ClassNode outerClass = node.getOuterClass();
+            addDynamicOuterClassAccessorsCallback(outerClass);
+        }
 
         classNode = previousClassNode;
     }
@@ -226,7 +232,10 @@ public class StaticCompilationVisitor extends StaticTypeCheckingVisitor {
         }
         super.visitMethod(node);
         checkForConstructorWithCSButClassWithout(node);
-        if (isStaticallyCompiled(node)) addDynamicOuterClassAccessorsCallback(node.getDeclaringClass());
+        if (isStaticallyCompiled(node)) {
+            ClassNode declaringClass = node.getDeclaringClass();
+            addDynamicOuterClassAccessorsCallback(declaringClass);
+        }
     }
 
     /**
diff --git a/src/test/org/codehaus/groovy/classgen/asm/sc/MixedModeStaticCompilationTest.groovy b/src/test/org/codehaus/groovy/classgen/asm/sc/MixedModeStaticCompilationTest.groovy
index 395e682..ebd2b63 100644
--- a/src/test/org/codehaus/groovy/classgen/asm/sc/MixedModeStaticCompilationTest.groovy
+++ b/src/test/org/codehaus/groovy/classgen/asm/sc/MixedModeStaticCompilationTest.groovy
@@ -21,14 +21,11 @@ package org.codehaus.groovy.classgen.asm.sc
 import groovy.transform.stc.StaticTypeCheckingTestCase
 import org.codehaus.groovy.control.customizers.ASTTransformationCustomizer
 
-class MixedModeStaticCompilationTest extends StaticTypeCheckingTestCase implements StaticCompilationTestSupport {
+final class MixedModeStaticCompilationTest extends StaticTypeCheckingTestCase implements StaticCompilationTestSupport {
+
     @Override
     protected void setUp() {
         super.setUp()
-        removeCustomizer()
-    }
-
-    private void removeCustomizer() {
         def customizers = config.compilationCustomizers
         customizers.removeAll { it instanceof ASTTransformationCustomizer }
     }
@@ -352,6 +349,21 @@ class MixedModeStaticCompilationTest extends StaticTypeCheckingTestCase implemen
             }
             assert new Test().strInSCInner() == 'hi'
         '''
+
+        // GROOVY-9328
+        assertScript '''
+            class Test {
+                private String str() { 'hi' }
+
+                class Inner {
+                    @groovy.transform.CompileStatic
+                    String outerStr() { str() }
+                }
+
+                String strInSCInner() { new Inner().outerStr() }
+            }
+            assert new Test().strInSCInner() == 'hi'
+        '''
     }
 
     void testSCAICCanAccessPrivateFieldsOfNonSCOuterClass() {
@@ -377,9 +389,26 @@ class MixedModeStaticCompilationTest extends StaticTypeCheckingTestCase implemen
 
                 @groovy.transform.CompileStatic
                 String strInSCAIC() {
-                    new Object() {
-                        String outerStr() { str() }
-                    }.outerStr()
+                    def callable = new java.util.concurrent.Callable<String>() {
+                        @Override String call() { str() }
+                    }
+                    callable.call()
+                }
+            }
+            assert new Test().strInSCAIC() == 'hi'
+        '''
+
+        // GROOVY-9328
+        assertScript '''
+            class Test {
+                private String str() { 'hi' }
+
+                def strInSCAIC() {
+                    def callable = new java.util.concurrent.Callable<String>() {
+                        @groovy.transform.CompileStatic
+                        @Override String call() { str() }
+                    }
+                    callable.call()
                 }
             }
             assert new Test().strInSCAIC() == 'hi'


[groovy] 01/06: GROOVY-8762, GROOVY-9332, GROOVY-9333: isInClosure() again for lambdas

Posted by su...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

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

commit 8996c8fb2922f5906c7d6945d433c541b82064e0
Author: Eric Milles <er...@thomsonreuters.com>
AuthorDate: Thu Dec 12 10:29:37 2019 +0800

    GROOVY-8762, GROOVY-9332, GROOVY-9333: isInClosure() again for lambdas
---
 .../groovy/classgen/asm/WriterController.java      |    2 +-
 src/test/groovy/transform/stc/LambdaTest.groovy    | 2513 +++++++++++---------
 2 files changed, 1355 insertions(+), 1160 deletions(-)

diff --git a/src/main/java/org/codehaus/groovy/classgen/asm/WriterController.java b/src/main/java/org/codehaus/groovy/classgen/asm/WriterController.java
index 7b88390..a1f6caa 100644
--- a/src/main/java/org/codehaus/groovy/classgen/asm/WriterController.java
+++ b/src/main/java/org/codehaus/groovy/classgen/asm/WriterController.java
@@ -285,7 +285,7 @@ public class WriterController {
     public boolean isInClosure() {
         return classNode.getOuterClass() != null
                 && classNode.getSuperClass().equals(ClassHelper.CLOSURE_TYPE)
-                && classNode.implementsInterface(ClassHelper.GENERATED_CLOSURE_Type);
+                && classNode.implementsAnyInterfaces(ClassHelper.GENERATED_CLOSURE_Type, ClassHelper.GENERATED_LAMBDA_TYPE);
     }
 
     public boolean isInClosureConstructor() {
diff --git a/src/test/groovy/transform/stc/LambdaTest.groovy b/src/test/groovy/transform/stc/LambdaTest.groovy
index 7d02748..d0e1259 100644
--- a/src/test/groovy/transform/stc/LambdaTest.groovy
+++ b/src/test/groovy/transform/stc/LambdaTest.groovy
@@ -16,919 +16,1006 @@
  *  specific language governing permissions and limitations
  *  under the License.
  */
-
 package groovy.transform.stc
 
-import groovy.test.GroovyTestCase
+import groovy.test.NotYetImplemented
+import groovy.transform.CompileStatic
+import org.junit.Test
+
+import static groovy.test.GroovyAssert.assertScript
+import static groovy.test.GroovyAssert.shouldFail
 
-class LambdaTest extends GroovyTestCase {
+@CompileStatic
+final class LambdaTest {
+
+    @Test
     void testFunction() {
         assertScript '''
-        import groovy.transform.CompileStatic
-        import java.util.stream.Collectors
-        import java.util.stream.Stream
-        
-        @CompileStatic
-        public class Test1 {
-            public static void main(String[] args) {
-                p();
-            }
-        
-            public static void p() {
-                assert [2, 3, 4] == [1, 2, 3].stream().map(e -> e.plus 1).collect(Collectors.toList());
+            import groovy.transform.CompileStatic
+            import java.util.stream.Collectors
+            import java.util.stream.Stream
+
+            @CompileStatic
+            public class Test1 {
+                public static void main(String[] args) {
+                    p();
+                }
+
+                public static void p() {
+                    assert [2, 3, 4] == [1, 2, 3].stream().map(e -> e.plus 1).collect(Collectors.toList());
+                }
             }
-        }
         '''
     }
 
+    @Test
     void testFunction2() {
         assertScript '''
-        import groovy.transform.CompileStatic
-        import java.util.stream.Collectors
-        import java.util.stream.Stream
-        
-        public class Test1 {
-            public static void main(String[] args) {
-                p();
-            }
-        
-            @CompileStatic
-            public static void p() {
-                assert [2, 3, 4] == [1, 2, 3].stream().map(e -> e.plus 1).collect(Collectors.toList());
+            import groovy.transform.CompileStatic
+            import java.util.stream.Collectors
+            import java.util.stream.Stream
+
+            public class Test1 {
+                public static void main(String[] args) {
+                    p();
+                }
+
+                @CompileStatic
+                public static void p() {
+                    assert [2, 3, 4] == [1, 2, 3].stream().map(e -> e.plus 1).collect(Collectors.toList());
+                }
             }
-        }
         '''
     }
 
-
+    @Test
     void testFunctionScript() {
         assertScript '''
-        import groovy.transform.CompileStatic
-        import java.util.stream.Collectors
-        import java.util.stream.Stream
-        
-        @CompileStatic
-        void p() {
-            assert [2, 3, 4] == [1, 2, 3].stream().map(e -> e + 1).collect(Collectors.toList());
-        }
-        
-        p()
+            import groovy.transform.CompileStatic
+            import java.util.stream.Collectors
+            import java.util.stream.Stream
+
+            @CompileStatic
+            void p() {
+                assert [2, 3, 4] == [1, 2, 3].stream().map(e -> e + 1).collect(Collectors.toList());
+            }
+
+            p()
         '''
     }
 
+    @Test
     void testFunctionScript2() {
         assertScript '''
-        import groovy.transform.CompileStatic
-        import java.util.stream.Collectors
-        import java.util.stream.Stream
-        
-        @CompileStatic
-        void p() {
-            assert [2, 3, 4] == [1, 2, 3].stream().map(e -> e.plus 1).collect(Collectors.toList());
-        }
-        
-        p()
+            import groovy.transform.CompileStatic
+            import java.util.stream.Collectors
+            import java.util.stream.Stream
+
+            @CompileStatic
+            void p() {
+                assert [2, 3, 4] == [1, 2, 3].stream().map(e -> e.plus 1).collect(Collectors.toList());
+            }
+
+            p()
         '''
     }
 
+    @Test
     void testBinaryOperator() {
         assertScript '''
-        import groovy.transform.CompileStatic
-        import java.util.stream.Collectors
-        import java.util.stream.Stream
-        
-        @CompileStatic
-        public class Test1 {
-            public static void main(String[] args) {
-                p();
-            }
-            
-            public static void p() {
-                assert 13 == [1, 2, 3].stream().reduce(7, (Integer r, Integer e) -> r + e);
+            import groovy.transform.CompileStatic
+            import java.util.stream.Collectors
+            import java.util.stream.Stream
+
+            @CompileStatic
+            public class Test1 {
+                public static void main(String[] args) {
+                    p();
+                }
+
+                public static void p() {
+                    assert 13 == [1, 2, 3].stream().reduce(7, (Integer r, Integer e) -> r + e);
+                }
             }
-        }
         '''
     }
 
-    // GROOVY-8917: Failed to infer parameter type of some SAM, e.g. BinaryOperator
+    @Test // GROOVY-8917: Failed to infer parameter type of some SAM, e.g. BinaryOperator
     void testBinaryOperatorWithoutExplicitTypeDef() {
         assertScript '''
-        import groovy.transform.CompileStatic
-        import java.util.stream.Collectors
-        import java.util.stream.Stream
-        
-        @CompileStatic
-        public class Test1 {
-            public static void main(String[] args) {
-                p();
-            }
-            
-            public static void p() {
-                assert 13 == [1, 2, 3].stream().reduce(7, (r, e) -> r + e);
+            import groovy.transform.CompileStatic
+            import java.util.stream.Collectors
+            import java.util.stream.Stream
+
+            @CompileStatic
+            public class Test1 {
+                public static void main(String[] args) {
+                    p();
+                }
+
+                public static void p() {
+                    assert 13 == [1, 2, 3].stream().reduce(7, (r, e) -> r + e);
+                }
             }
-        }
         '''
     }
 
+    @Test
     void testBinaryOperatorWithoutExplicitTypeDef2() {
         assertScript '''
-        import groovy.transform.CompileStatic
-        import java.util.stream.Collectors
-        import java.util.stream.Stream
-        import java.util.function.BinaryOperator
-        
-        @CompileStatic
-        public class Test1 {
-            public static void main(String[] args) {
-                p();
-            }
-            
-            public static void p() {
-                BinaryOperator<Integer> accumulator = (r, e) -> r + e
-                assert 13 == [1, 2, 3].stream().reduce(7, accumulator);
+            import groovy.transform.CompileStatic
+            import java.util.stream.Collectors
+            import java.util.stream.Stream
+            import java.util.function.BinaryOperator
+
+            @CompileStatic
+            public class Test1 {
+                public static void main(String[] args) {
+                    p();
+                }
+
+                public static void p() {
+                    BinaryOperator<Integer> accumulator = (r, e) -> r + e
+                    assert 13 == [1, 2, 3].stream().reduce(7, accumulator);
+                }
             }
-        }
         '''
     }
 
+    @Test
     void testConsumer() {
         assertScript '''
-        import groovy.transform.CompileStatic
-        import java.util.stream.Collectors
-        import java.util.stream.Stream
-        
-        @CompileStatic
-        public class Test1 {
-            public static void main(String[] args) {
-                p();
-            }
-            
-            public static void p() {
-                [1, 2, 3].stream().forEach(e -> { System.out.println(e + 1); });
+            import groovy.transform.CompileStatic
+            import java.util.stream.Collectors
+            import java.util.stream.Stream
+
+            @CompileStatic
+            public class Test1 {
+                public static void main(String[] args) {
+                    p();
+                }
+
+                public static void p() {
+                    [1, 2, 3].stream().forEach(e -> { System.out.println(e + 1); });
+                }
             }
-            
-        }
         '''
     }
 
+    @Test
     void testPredicate() {
         assertScript '''
-        import groovy.transform.CompileStatic
-        import java.util.stream.Collectors
-        import java.util.stream.Stream
-        
-        @CompileStatic
-        public class Test1 {
-            public static void main(String[] args) {
-                p();
-            }
-            
-            public static void p() {
-                def list = ['ab', 'bc', 'de']
-                list.removeIf(e -> e.startsWith("a"))
-                assert ['bc', 'de'] == list
+            import groovy.transform.CompileStatic
+            import java.util.stream.Collectors
+            import java.util.stream.Stream
+
+            @CompileStatic
+            public class Test1 {
+                public static void main(String[] args) {
+                    p();
+                }
+
+                public static void p() {
+                    def list = ['ab', 'bc', 'de']
+                    list.removeIf(e -> e.startsWith("a"))
+                    assert ['bc', 'de'] == list
+                }
             }
-        }
         '''
     }
 
+    @Test
     void testPredicateWithoutExplicitTypeDef() {
         assertScript '''
-        import groovy.transform.CompileStatic
-        import java.util.stream.Collectors
-        import java.util.stream.Stream
-        import java.util.function.Function
-        import java.util.function.Predicate
-        
-        @CompileStatic
-        public class Test1 {
-            public static void main(String[] args) {
-                p()
-            }
-        
-            public static void p() {
-                List<String> myList = Arrays.asList("a1", "a2", "b2", "b1", "c2", "c1")
-                Predicate<String> predicate = s -> s.startsWith("b")
-                Function<String, String> mapper = s -> s.toUpperCase()
-                
-                List<String> result =
-                        myList
-                            .stream()
-                            .filter(predicate)
-                            .map(mapper)
-                            .sorted()
-                            .collect(Collectors.toList())
-                
-                assert ['B1', 'B2'] == result
-            }
-        }
+            import groovy.transform.CompileStatic
+            import java.util.stream.Collectors
+            import java.util.stream.Stream
+            import java.util.function.Function
+            import java.util.function.Predicate
+
+            @CompileStatic
+            public class Test1 {
+                public static void main(String[] args) {
+                    p()
+                }
+
+                public static void p() {
+                    List<String> myList = Arrays.asList("a1", "a2", "b2", "b1", "c2", "c1")
+                    Predicate<String> predicate = s -> s.startsWith("b")
+                    Function<String, String> mapper = s -> s.toUpperCase()
+
+                    List<String> result =
+                            myList
+                                .stream()
+                                .filter(predicate)
+                                .map(mapper)
+                                .sorted()
+                                .collect(Collectors.toList())
+
+                    assert ['B1', 'B2'] == result
+                }
+            }
         '''
     }
 
+    @Test
     void testUnaryOperator() {
         assertScript '''
-        import groovy.transform.CompileStatic
-        import java.util.stream.Collectors
-        import java.util.stream.Stream
-        
-        @CompileStatic
-        public class Test1 {
-            public static void main(String[] args) {
-                p();
-            }
-            
-            public static void p() {
-                def list = [1, 2, 3]
-                list.replaceAll(e -> e + 10)
-                assert [11, 12, 13] == list
+            import groovy.transform.CompileStatic
+            import java.util.stream.Collectors
+            import java.util.stream.Stream
+
+            @CompileStatic
+            public class Test1 {
+                public static void main(String[] args) {
+                    p();
+                }
+
+                public static void p() {
+                    def list = [1, 2, 3]
+                    list.replaceAll(e -> e + 10)
+                    assert [11, 12, 13] == list
+                }
             }
-        }
         '''
     }
 
+    @Test
     void testBiConsumer() {
         assertScript '''
-        import groovy.transform.CompileStatic
-        import java.util.stream.Collectors
-        import java.util.stream.Stream
-        
-        @CompileStatic
-        public class Test1 {
-            public static void main(String[] args) {
-                p();
-            }
-            
-            public static void p() {
-                def map = [a: 1, b: 2, c: 3]
-                map.forEach((k, v) -> System.out.println(k + ":" + v));
+            import groovy.transform.CompileStatic
+            import java.util.stream.Collectors
+            import java.util.stream.Stream
+
+            @CompileStatic
+            public class Test1 {
+                public static void main(String[] args) {
+                    p();
+                }
+
+                public static void p() {
+                    def map = [a: 1, b: 2, c: 3]
+                    map.forEach((k, v) -> System.out.println(k + ":" + v));
+                }
             }
-        }
         '''
     }
 
+    @Test
     void testFunctionWithLocalVariables() {
         assertScript '''
-        import groovy.transform.CompileStatic
-        import java.util.stream.Collectors
-        import java.util.stream.Stream
-        
-        @CompileStatic
-        public class Test1 {
-            public static void main(String[] args) {
-                p();
-            }
-        
-            public static void p() {
-                String x = "#"
-                assert ['#1', '#2', '#3'] == [1, 2, 3].stream().map(e -> x + e).collect(Collectors.toList());
+            import groovy.transform.CompileStatic
+            import java.util.stream.Collectors
+            import java.util.stream.Stream
+
+            @CompileStatic
+            public class Test1 {
+                public static void main(String[] args) {
+                    p();
+                }
+
+                public static void p() {
+                    String x = "#"
+                    assert ['#1', '#2', '#3'] == [1, 2, 3].stream().map(e -> x + e).collect(Collectors.toList());
+                }
             }
-        }
         '''
     }
 
-
+    @Test
     void testFunctionWithLocalVariables2() {
         assertScript '''
-        import groovy.transform.CompileStatic
-        import java.util.stream.Collectors
-        import java.util.stream.Stream
-        
-        @CompileStatic
-        public class Test1 {
-            public static void main(String[] args) {
-                new Test1().p();
-            }
-        
-            public void p() {
-                String x = "#"
-                Integer y = 23
-                assert ['23#1', '23#2', '23#3'] == [1, 2, 3].stream().map(e -> '' + y + x + e).collect(Collectors.toList())
+            import groovy.transform.CompileStatic
+            import java.util.stream.Collectors
+            import java.util.stream.Stream
+
+            @CompileStatic
+            public class Test1 {
+                public static void main(String[] args) {
+                    new Test1().p();
+                }
+
+                public void p() {
+                    String x = "#"
+                    Integer y = 23
+                    assert ['23#1', '23#2', '23#3'] == [1, 2, 3].stream().map(e -> '' + y + x + e).collect(Collectors.toList())
+                }
             }
-        }
         '''
     }
 
     void testFunctionWithLocalVariables4() {
         assertScript '''
-        import groovy.transform.CompileStatic
-        import java.util.stream.Collectors
-        import java.util.stream.Stream
-        
-        @CompileStatic
-        public class Test4 {
-            public static void main(String[] args) {
-                new Test4().p();
-            }
-        
-            public void p() {
-                String x = "x";
-                StringBuilder y = new StringBuilder("y");
-                assert ['yx1', 'yx2', 'yx3'] == [1, 2, 3].stream().map(e -> y + x + e).collect(Collectors.toList());
+            import groovy.transform.CompileStatic
+            import java.util.stream.Collectors
+            import java.util.stream.Stream
+
+            @CompileStatic
+            public class Test4 {
+                public static void main(String[] args) {
+                    new Test4().p();
+                }
+
+                public void p() {
+                    String x = "x";
+                    StringBuilder y = new StringBuilder("y");
+                    assert ['yx1', 'yx2', 'yx3'] == [1, 2, 3].stream().map(e -> y + x + e).collect(Collectors.toList());
+                }
             }
-        }
         '''
     }
 
-    void testFunctionWithStaticMethodCall() {
+    @Test
+    void testFunctionWithLocalVariables5() {
         assertScript '''
-        import groovy.transform.CompileStatic
-        import java.util.stream.Collectors
-        import java.util.stream.Stream
-        
-        @CompileStatic
-        public class Test4 {
-            public static void main(String[] args) {
-                p();
+            import groovy.transform.CompileStatic
+            import java.util.stream.Collectors
+            import java.util.stream.Stream
+            import java.util.function.Function
+
+            @CompileStatic
+            public class Test1 {
+                public static void main(String[] args) {
+                    Function<Integer, String> f = p();
+                    assert '#1' == f(1)
+                }
+
+                static Function<Integer, String> p() {
+                    String x = "#"
+                    Function<Integer, String> f = (Integer e) -> x + e
+                    return f
+                }
             }
-        
-            public static void p() {
-                String x = "x";
-                StringBuilder y = new StringBuilder("y");
-                assert ['Hello yx1', 'Hello yx2', 'Hello yx3'] == [1, 2, 3].stream().map(e -> hello() + y + x + e).collect(Collectors.toList());
+        '''
+    }
+
+    @Test
+    void testFunctionWithLocalVariables6() {
+        assertScript '''
+            import groovy.transform.CompileStatic
+            import java.util.stream.Collectors
+            import java.util.stream.Stream
+            import java.util.function.Function
+
+            @CompileStatic
+            public class Test1 {
+                public static void main(String[] args) {
+                    Function<Integer, String> f = new Test1().p();
+                    assert '#1' == f(1)
+                }
+
+                Function<Integer, String> p() {
+                    String x = "#"
+                    Function<Integer, String> f = (Integer e) -> x + e
+                    return f
+                }
             }
-        
-            public static String hello() {
-                return "Hello ";
+        '''
+    }
+
+    @Test
+    void testFunctionWithStaticMethodCall() {
+        assertScript '''
+            import groovy.transform.CompileStatic
+            import java.util.stream.Collectors
+            import java.util.stream.Stream
+
+            @CompileStatic
+            public class Test4 {
+                public static void main(String[] args) {
+                    p();
+                }
+
+                public static void p() {
+                    String x = "x";
+                    StringBuilder y = new StringBuilder("y");
+                    assert ['Hello yx1', 'Hello yx2', 'Hello yx3'] == [1, 2, 3].stream().map(e -> hello() + y + x + e).collect(Collectors.toList());
+                }
+
+                public static String hello() {
+                    return "Hello ";
+                }
             }
-        }
         '''
     }
 
+    @Test
     void testFunctionWithStaticMethodCall2() {
         assertScript '''
-        import groovy.transform.CompileStatic
-        import java.util.stream.Collectors
-        import java.util.stream.Stream
-        
-        @CompileStatic
-        public class Test4 {
-            public static void main(String[] args) {
-                p();
-            }
-        
-            public static void p() {
-                String x = "x";
-                StringBuilder y = new StringBuilder("y");
-                assert ['Hello yx1', 'Hello yx2', 'Hello yx3'] == [1, 2, 3].stream().map(e -> Test4.hello() + y + x + e).collect(Collectors.toList());
-            }
-        
-            public static String hello() {
-                return "Hello ";
+            import groovy.transform.CompileStatic
+            import java.util.stream.Collectors
+            import java.util.stream.Stream
+
+            @CompileStatic
+            public class Test4 {
+                public static void main(String[] args) {
+                    p();
+                }
+
+                public static void p() {
+                    String x = "x";
+                    StringBuilder y = new StringBuilder("y");
+                    assert ['Hello yx1', 'Hello yx2', 'Hello yx3'] == [1, 2, 3].stream().map(e -> Test4.hello() + y + x + e).collect(Collectors.toList());
+                }
+
+                public static String hello() {
+                    return "Hello ";
+                }
             }
-        }
         '''
     }
 
+    @Test
     void testFunctionWithInstanceMethodCall() {
         assertScript '''
-        import groovy.transform.CompileStatic
-        import java.util.stream.Collectors
-        import java.util.stream.Stream
-        
-        @CompileStatic
-        public class Test4 {
-            public static void main(String[] args) {
-                new Test4().p();
-            }
-        
-            public void p() {
-                assert ['Hello Jochen', 'Hello Daniel'] == ["Jochen", "Daniel"].stream().map(e -> hello() + e).collect(Collectors.toList());
-            }
-        
-            public String hello() {
-                return "Hello ";
+            import groovy.transform.CompileStatic
+            import java.util.stream.Collectors
+            import java.util.stream.Stream
+
+            @CompileStatic
+            public class Test4 {
+                public static void main(String[] args) {
+                    new Test4().p();
+                }
+
+                public void p() {
+                    assert ['Hello Jochen', 'Hello Daniel'] == ["Jochen", "Daniel"].stream().map(e -> hello() + e).collect(Collectors.toList());
+                }
+
+                public String hello() {
+                    return "Hello ";
+                }
             }
-        }
         '''
     }
 
+    @Test
     void testFunctionInConstructor() {
         assertScript '''
-        import groovy.transform.CompileStatic
-        import java.util.stream.Collectors
-        import java.util.stream.Stream
-        
-        @CompileStatic
-        public class Test4 {
-            public static void main(String[] args) {
-                new Test4();
-            }
-            
-            public Test4() {
-                assert ['Hello Jochen', 'Hello Daniel'] == ["Jochen", "Daniel"].stream().map(e -> hello() + e).collect(Collectors.toList());
-            }
-        
-            public String hello() {
-                return "Hello ";
+            import groovy.transform.CompileStatic
+            import java.util.stream.Collectors
+            import java.util.stream.Stream
+
+            @CompileStatic
+            public class Test4 {
+                public static void main(String[] args) {
+                    new Test4();
+                }
+
+                public Test4() {
+                    assert ['Hello Jochen', 'Hello Daniel'] == ["Jochen", "Daniel"].stream().map(e -> hello() + e).collect(Collectors.toList());
+                }
+
+                public String hello() {
+                    return "Hello ";
+                }
             }
-        }
         '''
     }
 
+    @Test
     void testFunctionWithInstanceMethodCall2() {
         assertScript '''
-        import groovy.transform.CompileStatic
-        import java.util.stream.Collectors
-        import java.util.stream.Stream
-        
-        @CompileStatic
-        public class Test4 {
-            public static void main(String[] args) {
-                new Test4().p();
-            }
-        
-            public void p() {
-                assert ['Hello Jochen', 'Hello Daniel'] == ["Jochen", "Daniel"].stream().map(e -> this.hello() + e).collect(Collectors.toList());
-            }
-        
-            public String hello() {
-                return "Hello ";
+            import groovy.transform.CompileStatic
+            import java.util.stream.Collectors
+            import java.util.stream.Stream
+
+            @CompileStatic
+            public class Test4 {
+                public static void main(String[] args) {
+                    new Test4().p();
+                }
+
+                public void p() {
+                    assert ['Hello Jochen', 'Hello Daniel'] == ["Jochen", "Daniel"].stream().map(e -> this.hello() + e).collect(Collectors.toList());
+                }
+
+                public String hello() {
+                    return "Hello ";
+                }
             }
-        }
         '''
     }
 
+    @Test
     void testFunctionWithInstanceMethodCall3() {
         assertScript '''
-        import groovy.transform.CompileStatic
-        import java.util.stream.Collectors
-        import java.util.stream.Stream
-        
-        @CompileStatic
-        public class Test4 {
-            public static void main(String[] args) {
-                new Test4().p();
-            }
-        
-            public void p() {
-                assert ['Hello Jochen', 'Hello Daniel'] == ["Jochen", "Daniel"].stream().map(e -> hello(e)).collect(Collectors.toList());
-            }
-        
-            public String hello(String name) {
-                return "Hello $name";
+            import groovy.transform.CompileStatic
+            import java.util.stream.Collectors
+            import java.util.stream.Stream
+
+            @CompileStatic
+            public class Test4 {
+                public static void main(String[] args) {
+                    new Test4().p();
+                }
+
+                public void p() {
+                    assert ['Hello Jochen', 'Hello Daniel'] == ["Jochen", "Daniel"].stream().map(e -> hello(e)).collect(Collectors.toList());
+                }
+
+                public String hello(String name) {
+                    return "Hello $name";
+                }
             }
-        }
         '''
     }
 
+    @Test
     void testFunctionCall() {
         assertScript '''
-        import groovy.transform.CompileStatic
-        import java.util.stream.Collectors
-        import java.util.stream.Stream
-        import java.util.function.Function
-        
-        @CompileStatic
-        public class Test1 {
-            public static void main(String[] args) {
-                p();
-            }
-        
-            public static void p() {
-                Function<Integer, Integer> f = (Integer e) -> (Integer) (e + 1)
-                assert 2 == f(1)
+            import groovy.transform.CompileStatic
+            import java.util.stream.Collectors
+            import java.util.stream.Stream
+            import java.util.function.Function
+
+            @CompileStatic
+            public class Test1 {
+                public static void main(String[] args) {
+                    p();
+                }
+
+                public static void p() {
+                    Function<Integer, Integer> f = (Integer e) -> (Integer) (e + 1)
+                    assert 2 == f(1)
+                }
             }
-        }
         '''
     }
 
+    @Test
     void testFunctionCallWithoutExplicitTypeDef() {
         assertScript '''
-        import groovy.transform.CompileStatic
-        import java.util.stream.Collectors
-        import java.util.stream.Stream
-        import java.util.function.Function
-        
-        @CompileStatic
-        public class Test1 {
-            public static void main(String[] args) {
-                p();
-            }
-        
-            public static void p() {
-                Function<Integer, Integer> f = e -> e + 1
-                assert 2 == f(1)
+            import groovy.transform.CompileStatic
+            import java.util.stream.Collectors
+            import java.util.stream.Stream
+            import java.util.function.Function
+
+            @CompileStatic
+            public class Test1 {
+                public static void main(String[] args) {
+                    p();
+                }
+
+                public static void p() {
+                    Function<Integer, Integer> f = e -> e + 1
+                    assert 2 == f(1)
+                }
             }
-        }
         '''
     }
 
+    @Test
     void testFunctionCall2() {
         assertScript '''
-        import groovy.transform.CompileStatic
-        import java.util.stream.Collectors
-        import java.util.stream.Stream
-        import java.util.function.Function
-        
-        @CompileStatic
-        public class Test1 {
-            public static void main(String[] args) {
-                new Test1().p();
-            }
-        
-            public void p() {
-                Function<Integer, Integer> f = (Integer e) -> (Integer) (e + 1)
-                assert 2 == f(1)
+            import groovy.transform.CompileStatic
+            import java.util.stream.Collectors
+            import java.util.stream.Stream
+            import java.util.function.Function
+
+            @CompileStatic
+            public class Test1 {
+                public static void main(String[] args) {
+                    new Test1().p();
+                }
+
+                public void p() {
+                    Function<Integer, Integer> f = (Integer e) -> (Integer) (e + 1)
+                    assert 2 == f(1)
+                }
             }
-        }
         '''
     }
 
+    @Test
     void testFunctionCall3() {
         assertScript '''
-        import groovy.transform.CompileStatic
-        import java.util.stream.Collectors
-        import java.util.stream.Stream
-        import java.util.function.Function
-        
-        @CompileStatic
-        public class Test1 {
-            public static void main(String[] args) {
-                p();
-            }
-        
-            public static void p() {
-                Function<Integer, Integer> f = (Integer e) -> (Integer) (e + 1)
-                assert 2 == f.apply(1)
+            import groovy.transform.CompileStatic
+            import java.util.stream.Collectors
+            import java.util.stream.Stream
+            import java.util.function.Function
+
+            @CompileStatic
+            public class Test1 {
+                public static void main(String[] args) {
+                    p();
+                }
+
+                public static void p() {
+                    Function<Integer, Integer> f = (Integer e) -> (Integer) (e + 1)
+                    assert 2 == f.apply(1)
+                }
             }
-        }
         '''
     }
 
+    @Test
     void testConsumerCall() {
         assertScript '''
-        import groovy.transform.CompileStatic
-        import java.util.stream.Collectors
-        import java.util.stream.Stream
-        import java.util.function.Consumer
-        
-        @CompileStatic
-        public class Test1 {
-            public static void main(String[] args) {
-                p();
-            }
-        
-            public static void p() {
-                int r = 1
-                Consumer<Integer> c = (Integer e) -> { r += e }
-                c(2)
-                assert 3 == r
+            import groovy.transform.CompileStatic
+            import java.util.stream.Collectors
+            import java.util.stream.Stream
+            import java.util.function.Consumer
+
+            @CompileStatic
+            public class Test1 {
+                public static void main(String[] args) {
+                    p();
+                }
+
+                public static void p() {
+                    int r = 1
+                    Consumer<Integer> c = (Integer e) -> { r += e }
+                    c(2)
+                    assert 3 == r
+                }
             }
-        }
         '''
     }
 
+    @Test
     void testConsumerCallWithoutExplicitTypeDef() {
         assertScript '''
-        import groovy.transform.CompileStatic
-        import java.util.stream.Collectors
-        import java.util.stream.Stream
-        import java.util.function.Consumer
-        
-        @CompileStatic
-        public class Test1 {
-            public static void main(String[] args) {
-                p();
-            }
-        
-            public static void p() {
-                int r = 1
-                Consumer<Integer> c = e -> { r += e }
-                c(2)
-                assert 3 == r
+            import groovy.transform.CompileStatic
+            import java.util.stream.Collectors
+            import java.util.stream.Stream
+            import java.util.function.Consumer
+
+            @CompileStatic
+            public class Test1 {
+                public static void main(String[] args) {
+                    p();
+                }
+
+                public static void p() {
+                    int r = 1
+                    Consumer<Integer> c = e -> { r += e }
+                    c(2)
+                    assert 3 == r
+                }
             }
-        }
         '''
     }
 
+    @Test
     void testConsumerCall2() {
         assertScript '''
-        import groovy.transform.CompileStatic
-        import java.util.stream.Collectors
-        import java.util.stream.Stream
-        import java.util.function.Consumer
-        
-        @CompileStatic
-        public class Test1 {
-            public static void main(String[] args) {
-                new Test1().p();
-            }
-        
-            public void p() {
-                int r = 1
-                Consumer<Integer> c = (Integer e) -> { r += e }
-                c(2)
-                assert 3 == r
+            import groovy.transform.CompileStatic
+            import java.util.stream.Collectors
+            import java.util.stream.Stream
+            import java.util.function.Consumer
+
+            @CompileStatic
+            public class Test1 {
+                public static void main(String[] args) {
+                    new Test1().p();
+                }
+
+                public void p() {
+                    int r = 1
+                    Consumer<Integer> c = (Integer e) -> { r += e }
+                    c(2)
+                    assert 3 == r
+                }
             }
-        }
         '''
     }
 
+    @Test
     void testConsumerCall3() {
         assertScript '''
-        import groovy.transform.CompileStatic
-        import java.util.stream.Collectors
-        import java.util.stream.Stream
-        import java.util.function.Consumer
-        
-        @CompileStatic
-        public class Test1 {
-            public static void main(String[] args) {
-                p();
-            }
-        
-            public static void p() {
-                int r = 1
-                Consumer<Integer> c = (Integer e) -> { r += e }
-                c.accept(2)
-                assert 3 == r
-            }
-        }
-        '''
-    }
+            import groovy.transform.CompileStatic
+            import java.util.stream.Collectors
+            import java.util.stream.Stream
+            import java.util.function.Consumer
 
-    void testSamCall() {
+            @CompileStatic
+            public class Test1 {
+                public static void main(String[] args) {
+                    p();
+                }
+
+                public static void p() {
+                    int r = 1
+                    Consumer<Integer> c = (Integer e) -> { r += e }
+                    c.accept(2)
+                    assert 3 == r
+                }
+            }
+        '''
+    }
+
+    @Test
+    void testSamCall() {
         assertScript '''
-        import groovy.transform.CompileStatic
-        import java.util.stream.Collectors
-        import java.util.stream.Stream
-        
-        @CompileStatic
-        public class Test1 {
-            public static void main(String[] args) {
-                p();
+            import groovy.transform.CompileStatic
+            import java.util.stream.Collectors
+            import java.util.stream.Stream
+
+            @CompileStatic
+            public class Test1 {
+                public static void main(String[] args) {
+                    p();
+                }
+
+                public static void p() {
+                    SamCallable c = (int e) -> e
+                    assert 1 == c(1)
+                }
             }
-            
-            public static void p() {
-                SamCallable c = (int e) -> e
-                assert 1 == c(1)
+
+            @CompileStatic
+            interface SamCallable {
+                int call(int p);
             }
-        }
-        
-        @CompileStatic
-        interface SamCallable {
-            int call(int p);
-        }
         '''
     }
 
-
+    @Test
     void testSamCallWithoutExplicitTypeDef() {
         assertScript '''
-        import groovy.transform.CompileStatic
-        import java.util.stream.Collectors
-        import java.util.stream.Stream
-        
-        @CompileStatic
-        public class Test1 {
-            public static void main(String[] args) {
-                p();
+            import groovy.transform.CompileStatic
+            import java.util.stream.Collectors
+            import java.util.stream.Stream
+
+            @CompileStatic
+            public class Test1 {
+                public static void main(String[] args) {
+                    p();
+                }
+
+                public static void p() {
+                    SamCallable c = e -> e
+                    assert 1 == c(1)
+                }
             }
-            
-            public static void p() {
-                SamCallable c = e -> e
-                assert 1 == c(1)
+
+            @CompileStatic
+            interface SamCallable {
+                int call(int p);
             }
-        }
-        
-        @CompileStatic
-        interface SamCallable {
-            int call(int p);
-        }
         '''
     }
 
+    @Test
     void testSamCall2() {
         assertScript '''
-        import groovy.transform.CompileStatic
-        import java.util.stream.Collectors
-        import java.util.stream.Stream
-        
-        @CompileStatic
-        public class Test1 {
-            public static void main(String[] args) {
-                p();
+            import groovy.transform.CompileStatic
+            import java.util.stream.Collectors
+            import java.util.stream.Stream
+
+            @CompileStatic
+            public class Test1 {
+                public static void main(String[] args) {
+                    p();
+                }
+
+                public static void p() {
+                    SamCallable c = (int e) -> e // This is actually a closure(not a native lambda), because "Functional interface SamCallable is not an interface"
+                    assert 1 == c(1)
+                }
             }
-            
-            public static void p() {
-                SamCallable c = (int e) -> e // This is actually a closure(not a native lambda), because "Functional interface SamCallable is not an interface"
-                assert 1 == c(1)
+
+            @CompileStatic
+            abstract class SamCallable {
+                abstract int call(int p);
             }
-        }
-        
-        @CompileStatic
-        abstract class SamCallable {
-            abstract int call(int p);
-        }
         '''
     }
 
+    @Test
     void testFunctionWithUpdatingLocalVariable() {
         assertScript '''
-        import groovy.transform.CompileStatic
-        import java.util.stream.Collectors
-        import java.util.stream.Stream
-        
-        @CompileStatic
-        public class Test1 {
-            public static void main(String[] args) {
-                p();
-            }
-        
-            public static void p() {
-                int i = 1
-                assert [2, 4, 7] == [1, 2, 3].stream().map(e -> i += e).collect(Collectors.toList())
-                assert 7 == i
+            import groovy.transform.CompileStatic
+            import java.util.stream.Collectors
+            import java.util.stream.Stream
+
+            @CompileStatic
+            public class Test1 {
+                public static void main(String[] args) {
+                    p();
+                }
+
+                public static void p() {
+                    int i = 1
+                    assert [2, 4, 7] == [1, 2, 3].stream().map(e -> i += e).collect(Collectors.toList())
+                    assert 7 == i
+                }
             }
-        }
         '''
     }
 
+    @Test
     void testFunctionWithUpdatingLocalVariable2() {
         assertScript '''
-        import groovy.transform.CompileStatic
-        import java.util.stream.Collectors
-        import java.util.stream.Stream
-        
-        @CompileStatic
-        public class Test1 {
-            public static void main(String[] args) {
-                new Test1().p();
-            }
-        
-            public void p() {
-                int i = 1
-                assert [2, 4, 7] == [1, 2, 3].stream().map(e -> i += e).collect(Collectors.toList())
-                assert 7 == i
+            import groovy.transform.CompileStatic
+            import java.util.stream.Collectors
+            import java.util.stream.Stream
+
+            @CompileStatic
+            public class Test1 {
+                public static void main(String[] args) {
+                    new Test1().p();
+                }
+
+                public void p() {
+                    int i = 1
+                    assert [2, 4, 7] == [1, 2, 3].stream().map(e -> i += e).collect(Collectors.toList())
+                    assert 7 == i
+                }
             }
-        }
         '''
     }
 
+    @Test
     void testFunctionWithVariableDeclaration() {
         assertScript '''
-        import groovy.transform.CompileStatic
-        import java.util.stream.Collectors
-        import java.util.stream.Stream
-        import java.util.function.Function
-        
-        @CompileStatic
-        public class Test1 {
-            public static void main(String[] args) {
-                p()
-            }
-        
-            public static void p() {
-                Function<Integer, String> f = (Integer e) -> 'a' + e
-                assert ['a1', 'a2', 'a3'] == [1, 2, 3].stream().map(f).collect(Collectors.toList())
+            import groovy.transform.CompileStatic
+            import java.util.stream.Collectors
+            import java.util.stream.Stream
+            import java.util.function.Function
+
+            @CompileStatic
+            public class Test1 {
+                public static void main(String[] args) {
+                    p()
+                }
+
+                public static void p() {
+                    Function<Integer, String> f = (Integer e) -> 'a' + e
+                    assert ['a1', 'a2', 'a3'] == [1, 2, 3].stream().map(f).collect(Collectors.toList())
+                }
             }
-        }
-        
         '''
     }
 
+    @Test
     void testFunctionWithMixingVariableDeclarationAndMethodInvocation() {
         assertScript '''
-        import groovy.transform.CompileStatic
-        import java.util.stream.Collectors
-        import java.util.stream.Stream
-        import java.util.function.Function
-        
-        @CompileStatic
-        public class Test1 {
-            public static void main(String[] args) {
-                p()
-            }
-        
-            public static void p() {
-                String x = "#"
-                Integer y = 23
-                assert ['23#1', '23#2', '23#3'] == [1, 2, 3].stream().map(e -> '' + y + x + e).collect(Collectors.toList())
-            
-                Function<Integer, String> f = (Integer e) -> 'a' + e
-                assert ['a1', 'a2', 'a3'] == [1, 2, 3].stream().map(f).collect(Collectors.toList())
-                
-                assert [2, 3, 4] == [1, 2, 3].stream().map(e -> e.plus 1).collect(Collectors.toList());
+            import groovy.transform.CompileStatic
+            import java.util.stream.Collectors
+            import java.util.stream.Stream
+            import java.util.function.Function
+
+            @CompileStatic
+            public class Test1 {
+                public static void main(String[] args) {
+                    p()
+                }
+
+                public static void p() {
+                    String x = "#"
+                    Integer y = 23
+                    assert ['23#1', '23#2', '23#3'] == [1, 2, 3].stream().map(e -> '' + y + x + e).collect(Collectors.toList())
+
+                    Function<Integer, String> f = (Integer e) -> 'a' + e
+                    assert ['a1', 'a2', 'a3'] == [1, 2, 3].stream().map(f).collect(Collectors.toList())
+
+                    assert [2, 3, 4] == [1, 2, 3].stream().map(e -> e.plus 1).collect(Collectors.toList());
+                }
             }
-        }
-        
         '''
     }
 
+    @Test
     void testFunctionWithNestedLambda() {
         assertScript '''
-        import groovy.transform.CompileStatic
-        import java.util.stream.Collectors
-        import java.util.stream.Stream
-        
-        @CompileStatic
-        public class Test1 {
-            public static void main(String[] args) {
-                p()
-            }
-        
-            public static void p() {
-                [1, 2].stream().forEach(e -> {
-                    def list = ['a', 'b'].stream().map(f -> f + e).toList()
-                    if (1 == e) {
-                        assert ['a1', 'b1'] == list
-                    } else if (2 == e) {
-                        assert ['a2', 'b2'] == list
-                    }
-                })
-                
+            import groovy.transform.CompileStatic
+            import java.util.stream.Collectors
+            import java.util.stream.Stream
+
+            @CompileStatic
+            public class Test1 {
+                public static void main(String[] args) {
+                    p()
+                }
+
+                public static void p() {
+                    [1, 2].stream().forEach(e -> {
+                        def list = ['a', 'b'].stream().map(f -> f + e).toList()
+                        if (1 == e) {
+                            assert ['a1', 'b1'] == list
+                        } else if (2 == e) {
+                            assert ['a2', 'b2'] == list
+                        }
+                    })
+                }
             }
-        }
         '''
     }
 
+    @Test
     void testFunctionWithNestedLambda2() {
         assertScript '''
-        import groovy.transform.CompileStatic
-        import java.util.stream.Collectors
-        import java.util.stream.Stream
-        
-        @CompileStatic
-        public class Test1 {
-            public static void main(String[] args) {
-                p()
-            }
-        
-            public static void p() {
-                def list = ['a', 'b'].stream()
-                .map(e -> {
-                    [1, 2].stream().map(f -> e + f).toList()
-                }).toList()
-                
-                assert ['a1', 'a2'] == list[0]
-                assert ['b1', 'b2'] == list[1]
+            import groovy.transform.CompileStatic
+            import java.util.stream.Collectors
+            import java.util.stream.Stream
+
+            @CompileStatic
+            public class Test1 {
+                public static void main(String[] args) {
+                    p()
+                }
+
+                public static void p() {
+                    def list = ['a', 'b'].stream()
+                    .map(e -> {
+                        [1, 2].stream().map(f -> e + f).toList()
+                    }).toList()
+
+                    assert ['a1', 'a2'] == list[0]
+                    assert ['b1', 'b2'] == list[1]
+                }
             }
-        }
         '''
     }
 
+    @Test
     void testFunctionWithNestedLambda3() {
         assertScript '''
-        import groovy.transform.CompileStatic
-        import java.util.stream.Collectors
-        import java.util.stream.Stream
-        import java.util.function.Function
-        
-        @CompileStatic
-        public class Test1 {
-            public static void main(String[] args) {
-                p()
-            }
-        
-            public static void p() {
-                def list = ['a', 'b'].stream()
-                .map(e -> {
-                    Function<Integer, String> x = (Integer f) -> e + f
-                    [1, 2].stream().map(x).toList()
-                }).toList()
-                
-                assert ['a1', 'a2'] == list[0]
-                assert ['b1', 'b2'] == list[1]
+            import groovy.transform.CompileStatic
+            import java.util.stream.Collectors
+            import java.util.stream.Stream
+            import java.util.function.Function
+
+            @CompileStatic
+            public class Test1 {
+                public static void main(String[] args) {
+                    p()
+                }
+
+                public static void p() {
+                    def list = ['a', 'b'].stream()
+                    .map(e -> {
+                        Function<Integer, String> x = (Integer f) -> e + f
+                        [1, 2].stream().map(x).toList()
+                    }).toList()
+
+                    assert ['a1', 'a2'] == list[0]
+                    assert ['b1', 'b2'] == list[1]
+                }
             }
-        }
         '''
     }
 
+    @Test
     void testMixingLambdaAndMethodReference() {
         assertScript '''
             import java.util.stream.Collectors
-            
+
             @groovy.transform.CompileStatic
             void p() {
                 assert ['1', '2', '3'] == [1, 2, 3].stream().map(Object::toString).collect(Collectors.toList())
                 assert [2, 3, 4] == [1, 2, 3].stream().map(e -> e.plus 1).collect(Collectors.toList())
                 assert ['1', '2', '3'] == [1, 2, 3].stream().map(Object::toString).collect(Collectors.toList())
             }
-            
+
             p()
         '''
     }
 
+    @Test
     void testInitializeBlocks() {
         assertScript '''
             import java.util.stream.Collectors
-            
+
             @groovy.transform.CompileStatic
             class Test1 {
                 static sl
                 def il
                 static { sl = [1, 2, 3].stream().map(e -> e + 1).toList() }
-                 
+
                 {
                     il = [1, 2, 3].stream().map(e -> e + 2).toList()
                 }
             }
-            
+
             assert [2, 3, 4] == Test1.sl
             assert [3, 4, 5] == new Test1().il
         '''
     }
 
+    @Test @NotYetImplemented
     void testNestedLambdaAccessingInstanceFields() {
         assertScript '''
             @groovy.transform.CompileStatic
@@ -943,689 +1030,797 @@ class LambdaTest extends GroovyTestCase {
                     ['abc', 'def', 'ghi'].stream().filter(e -> strListHolder.strList.stream().anyMatch(c -> e.contains(c + b))).toList()
                 }
             }
-            
+
             assert ['abc'] == new Test1().p()
             assert ['abc'] == new Test1().p2()
         '''
     }
 
+    @Test // GROOVY-9332
+    void testStaticInitializeBlocks() {
+        assertScript '''
+            @groovy.transform.CompileStatic
+            class Test1 {
+                static list
+                static final int one = 1
+                static { list = [1, 2, 3].stream().map(e -> e + one).toList() }
+            }
+
+            assert [2, 3, 4] == Test1.list
+        '''
+    }
+
+    @Test @NotYetImplemented
+    void testStaticInitializeBlocks2() {
+        assertScript '''
+            @groovy.transform.CompileStatic
+            class Test1 {
+                static list
+                static int acc = 1
+                static { list = [1, 2, 3].stream().map(e -> acc += e).toList() }
+            }
+
+            assert [2, 4, 7] == Test1.list
+            assert 7 == Test1.acc
+        '''
+    }
+
+    @Test
+    void testAccessingThis() {
+        assertScript '''
+            import groovy.transform.CompileStatic
+            import java.util.function.Predicate
+
+            @CompileStatic
+            public class Test4 {
+                public static void main(String[] args) {
+                    new Test4().p();
+                }
+
+                public Test4 thisVar = this;
+
+                public void p() {
+                    Predicate<Test4> predicate = (Test4 s) -> { this === s }
+
+                    assert predicate.test(thisVar)
+                }
+            }
+        '''
+    }
+
+    @Test
+    void testAccessingThis2() {
+        assertScript '''
+            import groovy.transform.CompileStatic
+
+            @CompileStatic
+            public class Test4 {
+                public static void main(String[] args) {
+                    new Test4().p();
+                }
+
+                public String a = "a";
+
+                public void p() {
+                    assert ['a1', 'a2'] == [1, 2].stream().map(e -> this.a + e).toList();
+                }
+            }
+        '''
+    }
+
+    @Test
+    void testAccessingThis3() {
+        assertScript '''
+            import groovy.transform.CompileStatic
+
+            @CompileStatic
+            public class Test4 {
+                public static void main(String[] args) {
+                    new Test4().p();
+                }
+
+                public String a() { "a" }
+
+                public void p() {
+                    assert ['a1', 'a2'] == [1, 2].stream().map(e -> this.a() + e).toList();
+                }
+            }
+        '''
+    }
+
+    @Test
     void testSerialize() {
         assertScript '''
-        import java.util.function.Function
-        
-        interface SerializableFunction<T, R> extends Function<T, R>, Serializable {}
-        
-        @groovy.transform.CompileStatic
-        class Test1 {
-            def p() {
-                    def out = new ByteArrayOutputStream()
-                    out.withObjectOutputStream {
-                        SerializableFunction<Integer, String> f = ((Integer e) -> 'a' + e)
-                        it.writeObject(f)
-                    }
-                    
-                    return out.toByteArray()
+            import java.util.function.Function
+
+            interface SerializableFunction<T, R> extends Function<T, R>, Serializable {}
+
+            @groovy.transform.CompileStatic
+            class Test1 {
+                def p() {
+                        def out = new ByteArrayOutputStream()
+                        out.withObjectOutputStream {
+                            SerializableFunction<Integer, String> f = ((Integer e) -> 'a' + e)
+                            it.writeObject(f)
+                        }
+
+                        return out.toByteArray()
+                }
             }
-        }
 
-        assert new Test1().p().length > 0
+            assert new Test1().p().length > 0
         '''
     }
 
+    @Test
     void testSerializeFailed() {
-        def errMsg = shouldFail(NotSerializableException, '''
-        import java.util.function.Function
-        
-        @groovy.transform.CompileStatic
-        class Test1 {
-            def p() {
-                    def out = new ByteArrayOutputStream()
-                    out.withObjectOutputStream {
-                        Function<Integer, String> f = ((Integer e) -> 'a' + e)
-                        it.writeObject(f)
-                    }
-                    
-                    return out.toByteArray()
+        def err = shouldFail NotSerializableException, '''
+            import java.util.function.Function
+
+            @groovy.transform.CompileStatic
+            class Test1 {
+                def p() {
+                        def out = new ByteArrayOutputStream()
+                        out.withObjectOutputStream {
+                            Function<Integer, String> f = ((Integer e) -> 'a' + e)
+                            it.writeObject(f)
+                        }
+
+                        return out.toByteArray()
+                }
             }
-        }
 
-        new Test1().p()
-        ''')
+            new Test1().p()
+        '''
 
-        assert errMsg.contains('$Lambda$')
+        assert err.message.contains('$Lambda$')
     }
 
+    @Test
     void testDeserialize() {
         assertScript '''
-        package tests.lambda
-        import java.util.function.Function
-        
-        @groovy.transform.CompileStatic
-        class Test1 {
-            byte[] p() {
-                    def out = new ByteArrayOutputStream()
-                    out.withObjectOutputStream {
-                        SerializableFunction<Integer, String> f = ((Integer e) -> 'a' + e)
-                        it.writeObject(f)
+            package tests.lambda
+            import java.util.function.Function
+
+            @groovy.transform.CompileStatic
+            class Test1 {
+                byte[] p() {
+                        def out = new ByteArrayOutputStream()
+                        out.withObjectOutputStream {
+                            SerializableFunction<Integer, String> f = ((Integer e) -> 'a' + e)
+                            it.writeObject(f)
+                        }
+
+                        return out.toByteArray()
+                }
+
+                static void main(String[] args) {
+                    new ByteArrayInputStream(new Test1().p()).withObjectInputStream(Test1.class.classLoader) {
+                        SerializableFunction<Integer, String> f = (SerializableFunction<Integer, String>) it.readObject()
+                        assert 'a1' == f.apply(1)
                     }
-                    
-                    return out.toByteArray()
-            }
-            
-            static void main(String[] args) {
-                new ByteArrayInputStream(new Test1().p()).withObjectInputStream(Test1.class.classLoader) {
-                    SerializableFunction<Integer, String> f = (SerializableFunction<Integer, String>) it.readObject()
-                    assert 'a1' == f.apply(1)
                 }
+
+                interface SerializableFunction<T, R> extends Function<T, R>, Serializable {}
             }
-            
-            interface SerializableFunction<T, R> extends Function<T, R>, Serializable {}
-        }
         '''
     }
 
+    @Test
     void testDeserializeLambdaInInitializeBlock() {
         assertScript '''
             package tests.lambda
             import java.util.function.Function
-            
+
             @groovy.transform.CompileStatic
             class Test1 implements Serializable {
                 private static final long serialVersionUID = -1L;
                 String a = 'a'
                 SerializableFunction<Integer, String> f
-                 
+
                 {
                     f = ((Integer e) -> a + e)
                 }
-                
+
                 byte[] p() {
                     def out = new ByteArrayOutputStream()
                     out.withObjectOutputStream {
                         it.writeObject(f)
                     }
-                    
+
                     return out.toByteArray()
                 }
-                
+
                 static void main(String[] args) {
                     new ByteArrayInputStream(new Test1().p()).withObjectInputStream(Test1.class.classLoader) {
                         SerializableFunction<Integer, String> f = (SerializableFunction<Integer, String>) it.readObject()
                         assert 'a1' == f.apply(1)
                     }
                 }
-                
+
                 interface SerializableFunction<T, R> extends Function<T, R>, Serializable {}
             }
         '''
     }
 
+    @Test
     void testDeserializeLambdaInInitializeBlockShouldFail() {
-        def errMsg = shouldFail(NotSerializableException, '''
+        def err = shouldFail NotSerializableException, '''
             package tests.lambda
             import java.util.function.Function
-            
+
             @groovy.transform.CompileStatic
             class Test1 {
                 String a = 'a'
                 SerializableFunction<Integer, String> f
-                 
+
                 {
                     f = ((Integer e) -> a + e)
                 }
-                
+
                 byte[] p() {
                     def out = new ByteArrayOutputStream()
                     out.withObjectOutputStream {
                         it.writeObject(f)
                     }
-                    
+
                     return out.toByteArray()
                 }
-                
+
                 static void main(String[] args) {
                     new Test1().p()
                 }
-                
+
                 interface SerializableFunction<T, R> extends Function<T, R>, Serializable {}
             }
-        ''')
+        '''
 
-        assert errMsg.contains('tests.lambda.Test1')
+        assert err.message.contains('tests.lambda.Test1')
     }
 
-
+    @Test
     void testDeserialize2() {
         assertScript '''
-        import java.util.function.Function
-        
-        @groovy.transform.CompileStatic
-        class Test1 {
-            static byte[] p() {
-                    def out = new ByteArrayOutputStream()
-                    out.withObjectOutputStream {
-                        SerializableFunction<Integer, String> f = ((Integer e) -> 'a' + e)
-                        it.writeObject(f)
+            import java.util.function.Function
+
+            @groovy.transform.CompileStatic
+            class Test1 {
+                static byte[] p() {
+                        def out = new ByteArrayOutputStream()
+                        out.withObjectOutputStream {
+                            SerializableFunction<Integer, String> f = ((Integer e) -> 'a' + e)
+                            it.writeObject(f)
+                        }
+
+                        return out.toByteArray()
+                }
+
+                static void main(String[] args) {
+                    new ByteArrayInputStream(Test1.p()).withObjectInputStream(Test1.class.classLoader) {
+                        SerializableFunction<Integer, String> f = (SerializableFunction<Integer, String>) it.readObject()
+                        assert 'a1' == f.apply(1)
                     }
-                    
-                    return out.toByteArray()
-            }
-            
-            static void main(String[] args) {
-                new ByteArrayInputStream(Test1.p()).withObjectInputStream(Test1.class.classLoader) {
-                    SerializableFunction<Integer, String> f = (SerializableFunction<Integer, String>) it.readObject()
-                    assert 'a1' == f.apply(1)
                 }
+
+                interface SerializableFunction<T, R> extends Function<T, R>, Serializable {}
             }
-            
-            interface SerializableFunction<T, R> extends Function<T, R>, Serializable {}
-        }
         '''
     }
 
+    @Test
     void testDeserialize3() {
         assertScript '''
-        package tests.lambda
-        import java.util.function.Function
-        
-        @groovy.transform.CompileStatic
-        class Test1 {
-            byte[] p() {
-                    def out = new ByteArrayOutputStream()
-                    out.withObjectOutputStream {
-                        String c = 'a'
-                        SerializableFunction<Integer, String> f = (Integer e) -> c + e
-                        it.writeObject(f)
+            package tests.lambda
+            import java.util.function.Function
+
+            @groovy.transform.CompileStatic
+            class Test1 {
+                byte[] p() {
+                        def out = new ByteArrayOutputStream()
+                        out.withObjectOutputStream {
+                            String c = 'a'
+                            SerializableFunction<Integer, String> f = (Integer e) -> c + e
+                            it.writeObject(f)
+                        }
+
+                        return out.toByteArray()
+                }
+
+                static void main(String[] args) {
+                    new ByteArrayInputStream(new Test1().p()).withObjectInputStream(Test1.class.classLoader) {
+                        SerializableFunction<Integer, String> f = (SerializableFunction<Integer, String>) it.readObject()
+                        assert 'a1' == f.apply(1)
                     }
-                    
-                    return out.toByteArray()
-            }
-            
-            static void main(String[] args) {
-                new ByteArrayInputStream(new Test1().p()).withObjectInputStream(Test1.class.classLoader) {
-                    SerializableFunction<Integer, String> f = (SerializableFunction<Integer, String>) it.readObject()
-                    assert 'a1' == f.apply(1)
                 }
+
+                interface SerializableFunction<T, R> extends Function<T, R>, Serializable {}
             }
-            
-            interface SerializableFunction<T, R> extends Function<T, R>, Serializable {}
-        }
         '''
     }
 
+    @Test
     void testDeserialize4() {
         assertScript '''
-        package tests.lambda
-        import java.util.function.Function
-        
-        @groovy.transform.CompileStatic
-        class Test1 {
-            byte[] p() {
-                    def out = new ByteArrayOutputStream()
-                    String c = 'a'
-                    SerializableFunction<Integer, String> f = (Integer e) -> c + e
-                    out.withObjectOutputStream {
-                        it.writeObject(f)
-                    }
-                    
-                    return out.toByteArray()
-            }
-            
-            static void main(String[] args) {
-                new ByteArrayInputStream(new Test1().p()).withObjectInputStream(Test1.class.classLoader) {
-                    SerializableFunction<Integer, String> f = (SerializableFunction<Integer, String>) it.readObject()
-                    assert 'a1' == f.apply(1)
-                }
-            }
-            
-            interface SerializableFunction<T, R> extends Function<T, R>, Serializable {}
-        }
+            package tests.lambda
+            import java.util.function.Function
+
+            @groovy.transform.CompileStatic
+            class Test1 {
+                byte[] p() {
+                        def out = new ByteArrayOutputStream()
+                        String c = 'a'
+                        SerializableFunction<Integer, String> f = (Integer e) -> c + e
+                        out.withObjectOutputStream {
+                            it.writeObject(f)
+                        }
+
+                        return out.toByteArray()
+                }
+
+                static void main(String[] args) {
+                    new ByteArrayInputStream(new Test1().p()).withObjectInputStream(Test1.class.classLoader) {
+                        SerializableFunction<Integer, String> f = (SerializableFunction<Integer, String>) it.readObject()
+                        assert 'a1' == f.apply(1)
+                    }
+                }
+
+                interface SerializableFunction<T, R> extends Function<T, R>, Serializable {}
+            }
         '''
     }
 
+    @Test
     void testDeserialize5() {
         assertScript '''
-        package tests.lambda
-        import java.util.function.Function
-        
-        @groovy.transform.CompileStatic
-        class Test1 {
-            static byte[] p() {
-                    def out = new ByteArrayOutputStream()
-                    String c = 'a'
-                    SerializableFunction<Integer, String> f = (Integer e) -> c + e
-                    out.withObjectOutputStream {
-                        it.writeObject(f)
+            package tests.lambda
+            import java.util.function.Function
+
+            @groovy.transform.CompileStatic
+            class Test1 {
+                static byte[] p() {
+                        def out = new ByteArrayOutputStream()
+                        String c = 'a'
+                        SerializableFunction<Integer, String> f = (Integer e) -> c + e
+                        out.withObjectOutputStream {
+                            it.writeObject(f)
+                        }
+
+                        return out.toByteArray()
+                }
+
+                static void main(String[] args) {
+                    new ByteArrayInputStream(Test1.p()).withObjectInputStream(Test1.class.classLoader) {
+                        SerializableFunction<Integer, String> f = (SerializableFunction<Integer, String>) it.readObject()
+                        assert 'a1' == f.apply(1)
                     }
-                    
-                    return out.toByteArray()
-            }
-            
-            static void main(String[] args) {
-                new ByteArrayInputStream(Test1.p()).withObjectInputStream(Test1.class.classLoader) {
-                    SerializableFunction<Integer, String> f = (SerializableFunction<Integer, String>) it.readObject()
-                    assert 'a1' == f.apply(1)
                 }
+
+                interface SerializableFunction<T, R> extends Function<T, R>, Serializable {}
             }
-            
-            interface SerializableFunction<T, R> extends Function<T, R>, Serializable {}
-        }
         '''
     }
 
+    @Test
     void testDeserialize6InstanceFields() {
         assertScript '''
-        package tests.lambda
-        import java.util.function.Function
-        
-        @groovy.transform.CompileStatic
-        class Test1 implements Serializable {
-            private static final long serialVersionUID = -1L;
-            private String c = 'a'
-            
-            byte[] p() {
-                    def out = new ByteArrayOutputStream()
-                    SerializableFunction<Integer, String> f = (Integer e) -> c + e
-                    out.withObjectOutputStream {
-                        it.writeObject(f)
+            package tests.lambda
+            import java.util.function.Function
+
+            @groovy.transform.CompileStatic
+            class Test1 implements Serializable {
+                private static final long serialVersionUID = -1L;
+                private String c = 'a'
+
+                byte[] p() {
+                        def out = new ByteArrayOutputStream()
+                        SerializableFunction<Integer, String> f = (Integer e) -> c + e
+                        out.withObjectOutputStream {
+                            it.writeObject(f)
+                        }
+
+                        return out.toByteArray()
+                }
+
+                static void main(String[] args) {
+                    new ByteArrayInputStream(new Test1().p()).withObjectInputStream(Test1.class.classLoader) {
+                        SerializableFunction<Integer, String> f = (SerializableFunction<Integer, String>) it.readObject()
+                        assert 'a1' == f.apply(1)
                     }
-                    
-                    return out.toByteArray()
-            }
-            
-            static void main(String[] args) {
-                new ByteArrayInputStream(new Test1().p()).withObjectInputStream(Test1.class.classLoader) {
-                    SerializableFunction<Integer, String> f = (SerializableFunction<Integer, String>) it.readObject()
-                    assert 'a1' == f.apply(1)
                 }
+
+                interface SerializableFunction<T, R> extends Function<T, R>, Serializable {}
             }
-            
-            interface SerializableFunction<T, R> extends Function<T, R>, Serializable {}
-        }
         '''
     }
 
+    @Test
     void testDeserialize6InstanceFieldsShouldFail() {
-        def errMsg = shouldFail(NotSerializableException, '''
-        package tests.lambda
-        import java.util.function.Function
-        
-        @groovy.transform.CompileStatic
-        class Test1 {
-            private String c = 'a'
-            
-            byte[] p() {
-                    def out = new ByteArrayOutputStream()
-                    SerializableFunction<Integer, String> f = (Integer e) -> c + e
-                    out.withObjectOutputStream {
-                        it.writeObject(f)
+        def err = shouldFail NotSerializableException, '''
+            package tests.lambda
+            import java.util.function.Function
+
+            @groovy.transform.CompileStatic
+            class Test1 {
+                private String c = 'a'
+
+                byte[] p() {
+                        def out = new ByteArrayOutputStream()
+                        SerializableFunction<Integer, String> f = (Integer e) -> c + e
+                        out.withObjectOutputStream {
+                            it.writeObject(f)
+                        }
+
+                        return out.toByteArray()
+                }
+
+                static void main(String[] args) {
+                    new ByteArrayInputStream(new Test1().p()).withObjectInputStream(Test1.class.classLoader) {
+                        SerializableFunction<Integer, String> f = (SerializableFunction<Integer, String>) it.readObject()
+                        assert 'a1' == f.apply(1)
                     }
-                    
-                    return out.toByteArray()
-            }
-            
-            static void main(String[] args) {
-                new ByteArrayInputStream(new Test1().p()).withObjectInputStream(Test1.class.classLoader) {
-                    SerializableFunction<Integer, String> f = (SerializableFunction<Integer, String>) it.readObject()
-                    assert 'a1' == f.apply(1)
                 }
+
+                interface SerializableFunction<T, R> extends Function<T, R>, Serializable {}
             }
-            
-            interface SerializableFunction<T, R> extends Function<T, R>, Serializable {}
-        }
-        ''')
+        '''
 
-        assert errMsg.contains('tests.lambda.Test1')
+        assert err.message.contains('tests.lambda.Test1')
     }
 
+    @Test
     void testDeserialize6InstanceMethods() {
         assertScript '''
-        package tests.lambda
-        import java.util.function.Function
-        
-        @groovy.transform.CompileStatic
-        class Test1 implements Serializable {
-            private static final long serialVersionUID = -1L;
-            private String c() { 'a' }
-            
-            byte[] p() {
-                    def out = new ByteArrayOutputStream()
-                    SerializableFunction<Integer, String> f = (Integer e) -> c() + e
-                    out.withObjectOutputStream {
-                        it.writeObject(f)
+            package tests.lambda
+            import java.util.function.Function
+
+            @groovy.transform.CompileStatic
+            class Test1 implements Serializable {
+                private static final long serialVersionUID = -1L;
+                private String c() { 'a' }
+
+                byte[] p() {
+                        def out = new ByteArrayOutputStream()
+                        SerializableFunction<Integer, String> f = (Integer e) -> c() + e
+                        out.withObjectOutputStream {
+                            it.writeObject(f)
+                        }
+
+                        return out.toByteArray()
+                }
+
+                static void main(String[] args) {
+                    new ByteArrayInputStream(new Test1().p()).withObjectInputStream(Test1.class.classLoader) {
+                        SerializableFunction<Integer, String> f = (SerializableFunction<Integer, String>) it.readObject()
+                        assert 'a1' == f.apply(1)
                     }
-                    
-                    return out.toByteArray()
-            }
-            
-            static void main(String[] args) {
-                new ByteArrayInputStream(new Test1().p()).withObjectInputStream(Test1.class.classLoader) {
-                    SerializableFunction<Integer, String> f = (SerializableFunction<Integer, String>) it.readObject()
-                    assert 'a1' == f.apply(1)
                 }
+
+                interface SerializableFunction<T, R> extends Function<T, R>, Serializable {}
             }
-            
-            interface SerializableFunction<T, R> extends Function<T, R>, Serializable {}
-        }
         '''
     }
 
+    @Test
     void testDeserialize6InstanceMethodsShouldFail() {
-        def errMsg = shouldFail(NotSerializableException, '''
-        package tests.lambda
-        import java.util.function.Function
-        
-        @groovy.transform.CompileStatic
-        class Test1 {
-            private String c() { 'a' }
-            
-            byte[] p() {
-                    def out = new ByteArrayOutputStream()
-                    SerializableFunction<Integer, String> f = (Integer e) -> c() + e
-                    out.withObjectOutputStream {
-                        it.writeObject(f)
+        def err = shouldFail NotSerializableException, '''
+            package tests.lambda
+            import java.util.function.Function
+
+            @groovy.transform.CompileStatic
+            class Test1 {
+                private String c() { 'a' }
+
+                byte[] p() {
+                        def out = new ByteArrayOutputStream()
+                        SerializableFunction<Integer, String> f = (Integer e) -> c() + e
+                        out.withObjectOutputStream {
+                            it.writeObject(f)
+                        }
+
+                        return out.toByteArray()
+                }
+
+                static void main(String[] args) {
+                    new ByteArrayInputStream(new Test1().p()).withObjectInputStream(Test1.class.classLoader) {
+                        SerializableFunction<Integer, String> f = (SerializableFunction<Integer, String>) it.readObject()
+                        assert 'a1' == f.apply(1)
                     }
-                    
-                    return out.toByteArray()
-            }
-            
-            static void main(String[] args) {
-                new ByteArrayInputStream(new Test1().p()).withObjectInputStream(Test1.class.classLoader) {
-                    SerializableFunction<Integer, String> f = (SerializableFunction<Integer, String>) it.readObject()
-                    assert 'a1' == f.apply(1)
                 }
+
+                interface SerializableFunction<T, R> extends Function<T, R>, Serializable {}
             }
-            
-            interface SerializableFunction<T, R> extends Function<T, R>, Serializable {}
-        }
-        ''')
+        '''
 
-        assert errMsg.contains('tests.lambda.Test1')
+        assert err.message.contains('tests.lambda.Test1')
     }
 
+    @Test
     void testDeserialize7StaticFields() {
         assertScript '''
-        package tests.lambda
-        import java.util.function.Function
-        
-        @groovy.transform.CompileStatic
-        class Test1 {
-            private static final String c = 'a'
-            static byte[] p() {
-                    def out = new ByteArrayOutputStream()
-                    SerializableFunction<Integer, String> f = (Integer e) -> c + e
-                    out.withObjectOutputStream {
-                        it.writeObject(f)
+            package tests.lambda
+            import java.util.function.Function
+
+            @groovy.transform.CompileStatic
+            class Test1 {
+                private static final String c = 'a'
+                static byte[] p() {
+                        def out = new ByteArrayOutputStream()
+                        SerializableFunction<Integer, String> f = (Integer e) -> c + e
+                        out.withObjectOutputStream {
+                            it.writeObject(f)
+                        }
+
+                        return out.toByteArray()
+                }
+
+                static void main(String[] args) {
+                    new ByteArrayInputStream(Test1.p()).withObjectInputStream(Test1.class.classLoader) {
+                        SerializableFunction<Integer, String> f = (SerializableFunction<Integer, String>) it.readObject()
+                        assert 'a1' == f.apply(1)
                     }
-                    
-                    return out.toByteArray()
-            }
-            
-            static void main(String[] args) {
-                new ByteArrayInputStream(Test1.p()).withObjectInputStream(Test1.class.classLoader) {
-                    SerializableFunction<Integer, String> f = (SerializableFunction<Integer, String>) it.readObject()
-                    assert 'a1' == f.apply(1)
                 }
+
+                interface SerializableFunction<T, R> extends Function<T, R>, Serializable {}
             }
-            
-            interface SerializableFunction<T, R> extends Function<T, R>, Serializable {}
-        }
         '''
     }
 
-
+    @Test
     void testDeserialize7StaticMethods() {
         assertScript '''
-        package tests.lambda
-        import java.util.function.Function
-        
-        @groovy.transform.CompileStatic
-        class Test1 {
-            private static String c() { 'a' }
-            static byte[] p() {
-                    def out = new ByteArrayOutputStream()
-                    SerializableFunction<Integer, String> f = (Integer e) -> c() + e
-                    out.withObjectOutputStream {
-                        it.writeObject(f)
+            package tests.lambda
+            import java.util.function.Function
+
+            @groovy.transform.CompileStatic
+            class Test1 {
+                private static String c() { 'a' }
+                static byte[] p() {
+                        def out = new ByteArrayOutputStream()
+                        SerializableFunction<Integer, String> f = (Integer e) -> c() + e
+                        out.withObjectOutputStream {
+                            it.writeObject(f)
+                        }
+
+                        return out.toByteArray()
+                }
+
+                static void main(String[] args) {
+                    new ByteArrayInputStream(Test1.p()).withObjectInputStream(Test1.class.classLoader) {
+                        SerializableFunction<Integer, String> f = (SerializableFunction<Integer, String>) it.readObject()
+                        assert 'a1' == f.apply(1)
                     }
-                    
-                    return out.toByteArray()
-            }
-            
-            static void main(String[] args) {
-                new ByteArrayInputStream(Test1.p()).withObjectInputStream(Test1.class.classLoader) {
-                    SerializableFunction<Integer, String> f = (SerializableFunction<Integer, String>) it.readObject()
-                    assert 'a1' == f.apply(1)
                 }
+
+                interface SerializableFunction<T, R> extends Function<T, R>, Serializable {}
             }
-            
-            interface SerializableFunction<T, R> extends Function<T, R>, Serializable {}
-        }
         '''
     }
 
+    @Test
     void testDeserializeNestedLambda() {
         assertScript '''
-        import java.util.function.Function
-        
-        interface SerializableFunction<T, R> extends Function<T, R>, Serializable {}
-        
-        @groovy.transform.CompileStatic
-        class Test1 {
-            def p() {
-                    def out1 = new ByteArrayOutputStream()
-                    SerializableFunction<Integer, String> f1 = (Integer e) -> 'a' + e
-                    out1.withObjectOutputStream {
-                        it.writeObject(f1)
-                    }
-                    def result1 = out1.toByteArray()
-                    
-                    def out2 = new ByteArrayOutputStream()
-                    SerializableFunction<Integer, String> f2 = (Integer e) -> 'b' + e
-                    out2.withObjectOutputStream {
-                        it.writeObject(f2)
-                    }
-                    def result2 = out2.toByteArray()
-                    
-                    // nested lambda expression
-                    def out3 = new ByteArrayOutputStream()
-                    SerializableFunction<Integer, String> f3 = (Integer e) -> {
-                        SerializableFunction<Integer, String> nf = ((Integer ne) -> 'n' + ne)
-                        'c' + nf(e)
-                    }
-                    out3.withObjectOutputStream {
-                        it.writeObject(f3)
-                    }
-                    def result3 = out3.toByteArray()
-                    
-                    return [result1, result2, result3]
-            }
-        }
-        
-        def (byte[] serializedLambdaBytes1, byte[] serializedLambdaBytes2, byte[] serializedLambdaBytes3) = new Test1().p()
-        new ByteArrayInputStream(serializedLambdaBytes1).withObjectInputStream(Test1.class.classLoader) {
-            SerializableFunction<Integer, String> f = (SerializableFunction<Integer, String>) it.readObject()
-            assert 'a1' == f.apply(1)
-        }
-        
-        new ByteArrayInputStream(serializedLambdaBytes2).withObjectInputStream(Test1.class.classLoader) {
-            SerializableFunction<Integer, String> f = (SerializableFunction<Integer, String>) it.readObject()
-            assert 'b1' == f.apply(1)
-        }
-        
-        new ByteArrayInputStream(serializedLambdaBytes3).withObjectInputStream(Test1.class.classLoader) {
-            SerializableFunction<Integer, String> f = (SerializableFunction<Integer, String>) it.readObject()
-            assert 'cn1' == f.apply(1)
-        }
+            import java.util.function.Function
+
+            interface SerializableFunction<T, R> extends Function<T, R>, Serializable {}
+
+            @groovy.transform.CompileStatic
+            class Test1 {
+                def p() {
+                        def out1 = new ByteArrayOutputStream()
+                        SerializableFunction<Integer, String> f1 = (Integer e) -> 'a' + e
+                        out1.withObjectOutputStream {
+                            it.writeObject(f1)
+                        }
+                        def result1 = out1.toByteArray()
+
+                        def out2 = new ByteArrayOutputStream()
+                        SerializableFunction<Integer, String> f2 = (Integer e) -> 'b' + e
+                        out2.withObjectOutputStream {
+                            it.writeObject(f2)
+                        }
+                        def result2 = out2.toByteArray()
+
+                        // nested lambda expression
+                        def out3 = new ByteArrayOutputStream()
+                        SerializableFunction<Integer, String> f3 = (Integer e) -> {
+                            SerializableFunction<Integer, String> nf = ((Integer ne) -> 'n' + ne)
+                            'c' + nf(e)
+                        }
+                        out3.withObjectOutputStream {
+                            it.writeObject(f3)
+                        }
+                        def result3 = out3.toByteArray()
+
+                        return [result1, result2, result3]
+                }
+            }
+
+            def (byte[] serializedLambdaBytes1, byte[] serializedLambdaBytes2, byte[] serializedLambdaBytes3) = new Test1().p()
+            new ByteArrayInputStream(serializedLambdaBytes1).withObjectInputStream(Test1.class.classLoader) {
+                SerializableFunction<Integer, String> f = (SerializableFunction<Integer, String>) it.readObject()
+                assert 'a1' == f.apply(1)
+            }
+
+            new ByteArrayInputStream(serializedLambdaBytes2).withObjectInputStream(Test1.class.classLoader) {
+                SerializableFunction<Integer, String> f = (SerializableFunction<Integer, String>) it.readObject()
+                assert 'b1' == f.apply(1)
+            }
+
+            new ByteArrayInputStream(serializedLambdaBytes3).withObjectInputStream(Test1.class.classLoader) {
+                SerializableFunction<Integer, String> f = (SerializableFunction<Integer, String>) it.readObject()
+                assert 'cn1' == f.apply(1)
+            }
         '''
     }
 
+    @Test
     void testDeserializeNestedLambda2() {
         assertScript '''
-        import java.util.function.Function
-        
-        interface SerializableFunction<T, R> extends Function<T, R>, Serializable {}
-        
-        @groovy.transform.CompileStatic
-        class Test1 {
-            def p() {
-                    def out1 = new ByteArrayOutputStream()
-                    out1.withObjectOutputStream {
-                        SerializableFunction<Integer, String> f = ((Integer e) -> 'a' + e)
-                        it.writeObject(f)
-                    }
-                    def result1 = out1.toByteArray()
-                    
-                    def out2 = new ByteArrayOutputStream()
-                    out2.withObjectOutputStream {
-                        SerializableFunction<Integer, String> f = ((Integer e) -> 'b' + e)
-                        it.writeObject(f)
-                    }
-                    def result2 = out2.toByteArray()
-                    
-                    // nested lambda expression
-                    def out3 = new ByteArrayOutputStream()
-                    out3.withObjectOutputStream {
-                        SerializableFunction<Integer, String> f = ((Integer e) -> {
-                            SerializableFunction<Integer, String> nf = ((Integer ne) -> 'n' + ne)
-                            'c' + nf(e)
-                        })
-                        it.writeObject(f)
-                    }
-                    def result3 = out3.toByteArray()
-                    
-                    return [result1, result2, result3]
-            }
-        }
-        
-        def (byte[] serializedLambdaBytes1, byte[] serializedLambdaBytes2, byte[] serializedLambdaBytes3) = new Test1().p()
-        new ByteArrayInputStream(serializedLambdaBytes1).withObjectInputStream(Test1.class.classLoader) {
-            SerializableFunction<Integer, String> f = (SerializableFunction<Integer, String>) it.readObject()
-            assert 'a1' == f.apply(1)
-        }
-        
-        new ByteArrayInputStream(serializedLambdaBytes2).withObjectInputStream(Test1.class.classLoader) {
-            SerializableFunction<Integer, String> f = (SerializableFunction<Integer, String>) it.readObject()
-            assert 'b1' == f.apply(1)
-        }
-        
-        new ByteArrayInputStream(serializedLambdaBytes3).withObjectInputStream(Test1.class.classLoader) {
-            SerializableFunction<Integer, String> f = (SerializableFunction<Integer, String>) it.readObject()
-            assert 'cn1' == f.apply(1)
-        }
+            import java.util.function.Function
+
+            interface SerializableFunction<T, R> extends Function<T, R>, Serializable {}
+
+            @groovy.transform.CompileStatic
+            class Test1 {
+                def p() {
+                        def out1 = new ByteArrayOutputStream()
+                        out1.withObjectOutputStream {
+                            SerializableFunction<Integer, String> f = ((Integer e) -> 'a' + e)
+                            it.writeObject(f)
+                        }
+                        def result1 = out1.toByteArray()
+
+                        def out2 = new ByteArrayOutputStream()
+                        out2.withObjectOutputStream {
+                            SerializableFunction<Integer, String> f = ((Integer e) -> 'b' + e)
+                            it.writeObject(f)
+                        }
+                        def result2 = out2.toByteArray()
+
+                        // nested lambda expression
+                        def out3 = new ByteArrayOutputStream()
+                        out3.withObjectOutputStream {
+                            SerializableFunction<Integer, String> f = ((Integer e) -> {
+                                SerializableFunction<Integer, String> nf = ((Integer ne) -> 'n' + ne)
+                                'c' + nf(e)
+                            })
+                            it.writeObject(f)
+                        }
+                        def result3 = out3.toByteArray()
+
+                        return [result1, result2, result3]
+                }
+            }
+
+            def (byte[] serializedLambdaBytes1, byte[] serializedLambdaBytes2, byte[] serializedLambdaBytes3) = new Test1().p()
+            new ByteArrayInputStream(serializedLambdaBytes1).withObjectInputStream(Test1.class.classLoader) {
+                SerializableFunction<Integer, String> f = (SerializableFunction<Integer, String>) it.readObject()
+                assert 'a1' == f.apply(1)
+            }
+
+            new ByteArrayInputStream(serializedLambdaBytes2).withObjectInputStream(Test1.class.classLoader) {
+                SerializableFunction<Integer, String> f = (SerializableFunction<Integer, String>) it.readObject()
+                assert 'b1' == f.apply(1)
+            }
+
+            new ByteArrayInputStream(serializedLambdaBytes3).withObjectInputStream(Test1.class.classLoader) {
+                SerializableFunction<Integer, String> f = (SerializableFunction<Integer, String>) it.readObject()
+                assert 'cn1' == f.apply(1)
+            }
         '''
     }
 
+    @Test
     void testDeserializeNestedLambda3() {
         assertScript '''
-        import java.util.function.Function
-        
-        interface SerializableFunction<T, R> extends Function<T, R>, Serializable {}
-        
-        @groovy.transform.CompileStatic
-        class Test1 {
-            static p() {
-                    def out1 = new ByteArrayOutputStream()
-                    out1.withObjectOutputStream {
-                        SerializableFunction<Integer, String> f = ((Integer e) -> 'a' + e)
-                        it.writeObject(f)
-                    }
-                    def result1 = out1.toByteArray()
-                    
-                    def out2 = new ByteArrayOutputStream()
-                    out2.withObjectOutputStream {
-                        SerializableFunction<Integer, String> f = ((Integer e) -> 'b' + e)
-                        it.writeObject(f)
-                    }
-                    def result2 = out2.toByteArray()
-                    
-                    // nested lambda expression
-                    def out3 = new ByteArrayOutputStream()
-                    out3.withObjectOutputStream {
-                        SerializableFunction<Integer, String> f = ((Integer e) -> {
-                            SerializableFunction<Integer, String> nf = ((Integer ne) -> 'n' + ne)
-                            'c' + nf(e)
-                        })
-                        it.writeObject(f)
-                    }
-                    def result3 = out3.toByteArray()
-                    
-                    return [result1, result2, result3]
-            }
-        }
-        
-        def (byte[] serializedLambdaBytes1, byte[] serializedLambdaBytes2, byte[] serializedLambdaBytes3) = Test1.p()
-        new ByteArrayInputStream(serializedLambdaBytes1).withObjectInputStream(Test1.class.classLoader) {
-            SerializableFunction<Integer, String> f = (SerializableFunction<Integer, String>) it.readObject()
-            assert 'a1' == f.apply(1)
-        }
-        
-        new ByteArrayInputStream(serializedLambdaBytes2).withObjectInputStream(Test1.class.classLoader) {
-            SerializableFunction<Integer, String> f = (SerializableFunction<Integer, String>) it.readObject()
-            assert 'b1' == f.apply(1)
-        }
-        
-        new ByteArrayInputStream(serializedLambdaBytes3).withObjectInputStream(Test1.class.classLoader) {
-            SerializableFunction<Integer, String> f = (SerializableFunction<Integer, String>) it.readObject()
-            assert 'cn1' == f.apply(1)
-        }
+            import java.util.function.Function
+
+            interface SerializableFunction<T, R> extends Function<T, R>, Serializable {}
+
+            @groovy.transform.CompileStatic
+            class Test1 {
+                static p() {
+                        def out1 = new ByteArrayOutputStream()
+                        out1.withObjectOutputStream {
+                            SerializableFunction<Integer, String> f = ((Integer e) -> 'a' + e)
+                            it.writeObject(f)
+                        }
+                        def result1 = out1.toByteArray()
+
+                        def out2 = new ByteArrayOutputStream()
+                        out2.withObjectOutputStream {
+                            SerializableFunction<Integer, String> f = ((Integer e) -> 'b' + e)
+                            it.writeObject(f)
+                        }
+                        def result2 = out2.toByteArray()
+
+                        // nested lambda expression
+                        def out3 = new ByteArrayOutputStream()
+                        out3.withObjectOutputStream {
+                            SerializableFunction<Integer, String> f = ((Integer e) -> {
+                                SerializableFunction<Integer, String> nf = ((Integer ne) -> 'n' + ne)
+                                'c' + nf(e)
+                            })
+                            it.writeObject(f)
+                        }
+                        def result3 = out3.toByteArray()
+
+                        return [result1, result2, result3]
+                }
+            }
+
+            def (byte[] serializedLambdaBytes1, byte[] serializedLambdaBytes2, byte[] serializedLambdaBytes3) = Test1.p()
+            new ByteArrayInputStream(serializedLambdaBytes1).withObjectInputStream(Test1.class.classLoader) {
+                SerializableFunction<Integer, String> f = (SerializableFunction<Integer, String>) it.readObject()
+                assert 'a1' == f.apply(1)
+            }
+
+            new ByteArrayInputStream(serializedLambdaBytes2).withObjectInputStream(Test1.class.classLoader) {
+                SerializableFunction<Integer, String> f = (SerializableFunction<Integer, String>) it.readObject()
+                assert 'b1' == f.apply(1)
+            }
+
+            new ByteArrayInputStream(serializedLambdaBytes3).withObjectInputStream(Test1.class.classLoader) {
+                SerializableFunction<Integer, String> f = (SerializableFunction<Integer, String>) it.readObject()
+                assert 'cn1' == f.apply(1)
+            }
         '''
     }
 
+    @Test
     void testDeserializeNestedLambda4() {
         assertScript '''
-        import java.util.function.Function
-        
-        interface SerializableFunction<T, R> extends Function<T, R>, Serializable {}
-        
-        @groovy.transform.CompileStatic
-        class Test1 {
-            static p() {
-                    def out1 = new ByteArrayOutputStream()
-                    SerializableFunction<Integer, String> f1 = (Integer e) -> 'a' + e
-                    out1.withObjectOutputStream {
-                        it.writeObject(f1)
-                    }
-                    def result1 = out1.toByteArray()
-                    
-                    def out2 = new ByteArrayOutputStream()
-                    SerializableFunction<Integer, String> f2 = (Integer e) -> 'b' + e
-                    out2.withObjectOutputStream {
-                        it.writeObject(f2)
-                    }
-                    def result2 = out2.toByteArray()
-                    
-                    // nested lambda expression
-                    def out3 = new ByteArrayOutputStream()
-                    SerializableFunction<Integer, String> f3 = (Integer e) -> {
-                        SerializableFunction<Integer, String> nf = ((Integer ne) -> 'n' + ne)
-                        'c' + nf(e)
-                    }
-                    out3.withObjectOutputStream {
-                        it.writeObject(f3)
-                    }
-                    def result3 = out3.toByteArray()
-                    
-                    return [result1, result2, result3]
-            }
-        }
-        
-        def (byte[] serializedLambdaBytes1, byte[] serializedLambdaBytes2, byte[] serializedLambdaBytes3) = Test1.p()
-        new ByteArrayInputStream(serializedLambdaBytes1).withObjectInputStream(Test1.class.classLoader) {
-            SerializableFunction<Integer, String> f = (SerializableFunction<Integer, String>) it.readObject()
-            assert 'a1' == f.apply(1)
-        }
-        
-        new ByteArrayInputStream(serializedLambdaBytes2).withObjectInputStream(Test1.class.classLoader) {
-            SerializableFunction<Integer, String> f = (SerializableFunction<Integer, String>) it.readObject()
-            assert 'b1' == f.apply(1)
-        }
-        
-        new ByteArrayInputStream(serializedLambdaBytes3).withObjectInputStream(Test1.class.classLoader) {
-            SerializableFunction<Integer, String> f = (SerializableFunction<Integer, String>) it.readObject()
-            assert 'cn1' == f.apply(1)
-        }
+            import java.util.function.Function
+
+            interface SerializableFunction<T, R> extends Function<T, R>, Serializable {}
+
+            @groovy.transform.CompileStatic
+            class Test1 {
+                static p() {
+                        def out1 = new ByteArrayOutputStream()
+                        SerializableFunction<Integer, String> f1 = (Integer e) -> 'a' + e
+                        out1.withObjectOutputStream {
+                            it.writeObject(f1)
+                        }
+                        def result1 = out1.toByteArray()
+
+                        def out2 = new ByteArrayOutputStream()
+                        SerializableFunction<Integer, String> f2 = (Integer e) -> 'b' + e
+                        out2.withObjectOutputStream {
+                            it.writeObject(f2)
+                        }
+                        def result2 = out2.toByteArray()
+
+                        // nested lambda expression
+                        def out3 = new ByteArrayOutputStream()
+                        SerializableFunction<Integer, String> f3 = (Integer e) -> {
+                            SerializableFunction<Integer, String> nf = ((Integer ne) -> 'n' + ne)
+                            'c' + nf(e)
+                        }
+                        out3.withObjectOutputStream {
+                            it.writeObject(f3)
+                        }
+                        def result3 = out3.toByteArray()
+
+                        return [result1, result2, result3]
+                }
+            }
+
+            def (byte[] serializedLambdaBytes1, byte[] serializedLambdaBytes2, byte[] serializedLambdaBytes3) = Test1.p()
+            new ByteArrayInputStream(serializedLambdaBytes1).withObjectInputStream(Test1.class.classLoader) {
+                SerializableFunction<Integer, String> f = (SerializableFunction<Integer, String>) it.readObject()
+                assert 'a1' == f.apply(1)
+            }
+
+            new ByteArrayInputStream(serializedLambdaBytes2).withObjectInputStream(Test1.class.classLoader) {
+                SerializableFunction<Integer, String> f = (SerializableFunction<Integer, String>) it.readObject()
+                assert 'b1' == f.apply(1)
+            }
+
+            new ByteArrayInputStream(serializedLambdaBytes3).withObjectInputStream(Test1.class.classLoader) {
+                SerializableFunction<Integer, String> f = (SerializableFunction<Integer, String>) it.readObject()
+                assert 'cn1' == f.apply(1)
+            }
         '''
     }
-
 }