Quantcast

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
|  
Report Content as Inappropriate

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

paulk
Repository: groovy
Updated Branches:
  refs/heads/GROOVY_2_5_X 5a09c0471 -> 6f3827c36


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/6f3827c3
Tree: http://git-wip-us.apache.org/repos/asf/groovy/tree/6f3827c3
Diff: http://git-wip-us.apache.org/repos/asf/groovy/diff/6f3827c3

Branch: refs/heads/GROOVY_2_5_X
Commit: 6f3827c364e8ae560dd91bc1b4889af2f807781c
Parents: 5a09c04
Author: paulk <[hidden email]>
Authored: Fri Mar 10 17:27:55 2017 +1000
Committer: paulk <[hidden email]>
Committed: Mon Mar 20 16:50:17 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/6f3827c3/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/6f3827c3/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 {

Loading...