You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@groovy.apache.org by sh...@apache.org on 2016/06/16 03:29:20 UTC
groovy git commit: GROOVY-7863: Statically compiled calls to private
outer class methods fail with multiple levels of nesting (closes #350)
Repository: groovy
Updated Branches:
refs/heads/master b90c0b69c -> 1aba75218
GROOVY-7863: Statically compiled calls to private outer class methods fail with multiple levels of nesting (closes #350)
Project: http://git-wip-us.apache.org/repos/asf/groovy/repo
Commit: http://git-wip-us.apache.org/repos/asf/groovy/commit/1aba7521
Tree: http://git-wip-us.apache.org/repos/asf/groovy/tree/1aba7521
Diff: http://git-wip-us.apache.org/repos/asf/groovy/diff/1aba7521
Branch: refs/heads/master
Commit: 1aba752185bdd187d35b538b92a02f45e368634b
Parents: b90c0b6
Author: Shil Sinha <sh...@gmail.com>
Authored: Tue Jun 14 18:27:08 2016 -0400
Committer: Shil Sinha <sh...@gmail.com>
Committed: Wed Jun 15 16:38:40 2016 -0400
----------------------------------------------------------------------
.../classgen/asm/sc/StaticInvocationWriter.java | 14 +++++++------
.../sc/MethodCallsStaticCompilationTest.groovy | 22 ++++++++++++++++++++
2 files changed, 30 insertions(+), 6 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/groovy/blob/1aba7521/src/main/org/codehaus/groovy/classgen/asm/sc/StaticInvocationWriter.java
----------------------------------------------------------------------
diff --git a/src/main/org/codehaus/groovy/classgen/asm/sc/StaticInvocationWriter.java b/src/main/org/codehaus/groovy/classgen/asm/sc/StaticInvocationWriter.java
index b301e74..4fd48c9 100644
--- a/src/main/org/codehaus/groovy/classgen/asm/sc/StaticInvocationWriter.java
+++ b/src/main/org/codehaus/groovy/classgen/asm/sc/StaticInvocationWriter.java
@@ -187,13 +187,15 @@ public class StaticInvocationWriter extends InvocationWriter {
MethodNode bridge = bridges==null?null:bridges.get(target);
if (bridge != null) {
Expression fixedReceiver = receiver;
- ClassNode classNode = implicitThis?controller.getClassNode():null;
ClassNode declaringClass = bridge.getDeclaringClass();
- if (implicitThis && !controller.isInClosure()
- && !classNode.isDerivedFrom(declaringClass)
- && !classNode.implementsInterface(declaringClass)
- && classNode instanceof InnerClassNode) {
- fixedReceiver = new PropertyExpression(new ClassExpression(classNode.getOuterClass()), "this");
+ if (implicitThis && !controller.isInClosure()) {
+ ClassNode classNode = controller.getClassNode();
+ while (!classNode.isDerivedFrom(declaringClass)
+ && !classNode.implementsInterface(declaringClass)
+ && classNode instanceof InnerClassNode) {
+ classNode = classNode.getOuterClass();
+ }
+ fixedReceiver = new PropertyExpression(new ClassExpression(classNode), "this");
}
ArgumentListExpression newArgs = new ArgumentListExpression(target.isStatic()?new ConstantExpression(null):fixedReceiver);
for (Expression expression : args.getExpressions()) {
http://git-wip-us.apache.org/repos/asf/groovy/blob/1aba7521/src/test/org/codehaus/groovy/classgen/asm/sc/MethodCallsStaticCompilationTest.groovy
----------------------------------------------------------------------
diff --git a/src/test/org/codehaus/groovy/classgen/asm/sc/MethodCallsStaticCompilationTest.groovy b/src/test/org/codehaus/groovy/classgen/asm/sc/MethodCallsStaticCompilationTest.groovy
index c678017..d392153 100644
--- a/src/test/org/codehaus/groovy/classgen/asm/sc/MethodCallsStaticCompilationTest.groovy
+++ b/src/test/org/codehaus/groovy/classgen/asm/sc/MethodCallsStaticCompilationTest.groovy
@@ -217,6 +217,28 @@ import groovy.transform.TypeCheckingMode//import org.codehaus.groovy.classgen.as
'''
}
+ void testDoublyNestedPrivateMethodAccess() {
+ assertScript '''
+ class A {
+ private int bar() { 123 }
+
+ class B {
+
+ int testInner() { new C().barInner() }
+
+ class C {
+ int barInner() { bar() }
+ }
+ }
+
+ int test() {
+ new B().testInner()
+ }
+ }
+ assert new A().test() == 123
+ '''
+ }
+
public static class Base {
protected int foo() {
123