groovy git commit: GROOVY-8043: NPE compiling Memoized method with AIC (closes #511)

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

groovy git commit: GROOVY-8043: NPE compiling Memoized method with AIC (closes #511)

paulk
Repository: groovy
Updated Branches:
  refs/heads/master 97d8c9ebd -> 2211af50c


GROOVY-8043: NPE compiling Memoized method with AIC (closes #511)


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

Branch: refs/heads/master
Commit: 2211af50cd83dc7444c3db0b3df135cf9657f1bf
Parents: 97d8c9e
Author: paulk <[hidden email]>
Authored: Fri Mar 10 17:27:55 2017 +1000
Committer: paulk <[hidden email]>
Committed: Mon Mar 20 16:48:46 2017 +1000

----------------------------------------------------------------------
 .../groovy/transform/MemoizedASTTransformation.java     |  7 ++++++-
 .../transform/MemoizedASTTransformationTest.groovy      | 12 ++++++++++++
 2 files changed, 18 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/groovy/blob/2211af50/src/main/org/codehaus/groovy/transform/MemoizedASTTransformation.java
----------------------------------------------------------------------
diff --git a/src/main/org/codehaus/groovy/transform/MemoizedASTTransformation.java b/src/main/org/codehaus/groovy/transform/MemoizedASTTransformation.java
index 8067cba..2769a33 100644
--- a/src/main/org/codehaus/groovy/transform/MemoizedASTTransformation.java
+++ b/src/main/org/codehaus/groovy/transform/MemoizedASTTransformation.java
@@ -25,6 +25,7 @@ import org.codehaus.groovy.ast.AnnotationNode;
 import org.codehaus.groovy.ast.ClassHelper;
 import org.codehaus.groovy.ast.ClassNode;
 import org.codehaus.groovy.ast.FieldNode;
+import org.codehaus.groovy.ast.InnerClassNode;
 import org.codehaus.groovy.ast.MethodNode;
 import org.codehaus.groovy.ast.Parameter;
 import org.codehaus.groovy.ast.expr.ClosureExpression;
@@ -109,7 +110,11 @@ public class MemoizedASTTransformation extends AbstractASTTransformation {
             newCode.addStatement(returnS(closureCallExpression));
             methodNode.setCode(newCode);
             VariableScopeVisitor visitor = new VariableScopeVisitor(source);
-            visitor.visitClass(ownerClassNode);
+            if (ownerClassNode instanceof InnerClassNode) {
+                visitor.visitClass(((InnerClassNode) ownerClassNode).getOuterMostClass());
+            } else {
+                visitor.visitClass(ownerClassNode);
+            }
         }
     }
 

http://git-wip-us.apache.org/repos/asf/groovy/blob/2211af50/src/test/org/codehaus/groovy/transform/MemoizedASTTransformationTest.groovy
----------------------------------------------------------------------
diff --git a/src/test/org/codehaus/groovy/transform/MemoizedASTTransformationTest.groovy b/src/test/org/codehaus/groovy/transform/MemoizedASTTransformationTest.groovy
index e75138d..77e3f61 100644
--- a/src/test/org/codehaus/groovy/transform/MemoizedASTTransformationTest.groovy
+++ b/src/test/org/codehaus/groovy/transform/MemoizedASTTransformationTest.groovy
@@ -193,6 +193,18 @@ class MemoizedASTTransformationTest extends GroovyTestCase {
         assertEquals(MemoizedTestClass.privateStaticMethodWithParams(20, 5), 15)
         assertEquals(MemoizedTestClass.privateStaticMethodWithParamsCounter, 3)
     }
+
+    void testMemoizedAIC_Groovy8043() {
+        assertScript '''
+            class A {}
+            assert new A() {
+                @groovy.transform.Memoized()
+                String a() {
+                    return "a"
+                }
+            }.a() == 'a'
+        '''
+    }
 }
 
 class MemoizedTestClass2 {