groovy git commit: GROOVY-8764: Closure inside an anonymous class uses wrong outside class instance with @CS (refactor for master to align with 2_5_X)

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

groovy git commit: GROOVY-8764: Closure inside an anonymous class uses wrong outside class instance with @CS (refactor for master to align with 2_5_X)

paulk
Repository: groovy
Updated Branches:
  refs/heads/master 55d195b5d -> 815cc4b88


GROOVY-8764: Closure inside an anonymous class uses wrong outside class instance with @CS (refactor for master to align with 2_5_X)


Project: http://git-wip-us.apache.org/repos/asf/groovy/repo
Commit: http://git-wip-us.apache.org/repos/asf/groovy/commit/815cc4b8
Tree: http://git-wip-us.apache.org/repos/asf/groovy/tree/815cc4b8
Diff: http://git-wip-us.apache.org/repos/asf/groovy/diff/815cc4b8

Branch: refs/heads/master
Commit: 815cc4b88086b170c3989d39c710d141f962f06e
Parents: 55d195b
Author: Paul King <[hidden email]>
Authored: Wed Oct 10 21:01:11 2018 +1000
Committer: Paul King <[hidden email]>
Committed: Wed Oct 10 21:01:11 2018 +1000

----------------------------------------------------------------------
 .../java/org/codehaus/groovy/classgen/asm/ClosureWriter.java | 8 ++++----
 .../groovy/classgen/asm/sc/StaticTypesLambdaWriter.java      | 2 +-
 2 files changed, 5 insertions(+), 5 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/groovy/blob/815cc4b8/src/main/java/org/codehaus/groovy/classgen/asm/ClosureWriter.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/codehaus/groovy/classgen/asm/ClosureWriter.java b/src/main/java/org/codehaus/groovy/classgen/asm/ClosureWriter.java
index 6ca8574..d9a783b 100644
--- a/src/main/java/org/codehaus/groovy/classgen/asm/ClosureWriter.java
+++ b/src/main/java/org/codehaus/groovy/classgen/asm/ClosureWriter.java
@@ -251,7 +251,7 @@ public class ClosureWriter {
         }
 
         // let's make the constructor
-        BlockStatement block = createBlockStatementForConstructor(expression);
+        BlockStatement block = createBlockStatementForConstructor(expression, outerClass, classNode);
 
         // let's assign all the parameter fields from the outer context
         addFieldsAndGettersForLocalVariables(answer, localVariableParams);
@@ -302,14 +302,14 @@ public class ClosureWriter {
         }
     }
 
-    protected BlockStatement createBlockStatementForConstructor(ClosureExpression expression) {
+    protected BlockStatement createBlockStatementForConstructor(ClosureExpression expression, ClassNode outerClass, ClassNode thisClassNode) {
         BlockStatement block = new BlockStatement();
         // this block does not get a source position, because we don't
         // want this synthetic constructor to show up in corbertura reports
-        VariableExpression outer = new VariableExpression(OUTER_INSTANCE);
+        VariableExpression outer = new VariableExpression(OUTER_INSTANCE, outerClass);
         outer.setSourcePosition(expression);
         block.getVariableScope().putReferencedLocalVariable(outer);
-        VariableExpression thisObject = new VariableExpression(THIS_OBJECT);
+        VariableExpression thisObject = new VariableExpression(THIS_OBJECT, thisClassNode);
         thisObject.setSourcePosition(expression);
         block.getVariableScope().putReferencedLocalVariable(thisObject);
         TupleExpression conArgs = new TupleExpression(outer, thisObject);

http://git-wip-us.apache.org/repos/asf/groovy/blob/815cc4b8/src/main/java/org/codehaus/groovy/classgen/asm/sc/StaticTypesLambdaWriter.java
----------------------------------------------------------------------
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 45cc509..381262f 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
@@ -309,7 +309,7 @@ public class StaticTypesLambdaWriter extends LambdaWriter {
         Parameter[] localVariableParameters = syntheticLambdaMethodNode.getNodeMetaData(LAMBDA_SHARED_VARIABLES);
 
         addFieldsAndGettersForLocalVariables(answer, localVariableParameters);
-        ConstructorNode constructorNode = addConstructor(expression, localVariableParameters, answer, createBlockStatementForConstructor(expression));
+        ConstructorNode constructorNode = addConstructor(expression, localVariableParameters, answer, createBlockStatementForConstructor(expression, outerClass, classNode));
         constructorNode.putNodeMetaData(IS_GENERATED_CONSTRUCTOR, Boolean.TRUE);
 
         Parameter enclosingThisParameter = syntheticLambdaMethodNode.getParameters()[0];