Skip to content

Commit

Permalink
GROOVY-9938
Browse files Browse the repository at this point in the history
  • Loading branch information
eric-milles committed Feb 13, 2021
1 parent d1022ea commit ac96a1c
Show file tree
Hide file tree
Showing 8 changed files with 550 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5774,4 +5774,99 @@ public void testCompileStatic9918() {

runConformTest(sources, "");
}

@Test
public void testCompileStatic9938() {
//@formatter:off
String[] sources = {
"Main.groovy",
"@groovy.transform.CompileStatic\n" +
"class Main {\n" +
" interface I {\n" +
" void m(@DelegatesTo(value=D, strategy=Closure.DELEGATE_FIRST) Closure<?> c)\n" +
" }\n" +
" static class C implements I {\n" +
" void m(@DelegatesTo(value=D, strategy=Closure.DELEGATE_FIRST) Closure<?> c) {\n" +
" new D().with(c)\n" +
" }\n" +
" }\n" +
" static class D {\n" +
" void f() {\n" +
" print 'works'\n" +
" }\n" +
" }\n" +
" static main(args) {\n" +
" new C().m { f() }\n" +
" }\n" +
"}\n",
};
//@formatter:on

runConformTest(sources, "works");
}

@Test
public void testCompileStatic9938a() {
//@formatter:off
String[] sources = {
"Main.groovy",
"@groovy.transform.CompileStatic\n" +
"class Main {\n" +
" interface I {\n" +
" void m(@DelegatesTo(value=D, strategy=Closure.DELEGATE_FIRST) Closure<?> c)\n" +
" }\n" +
" static class X implements I {\n" +
" void m(@DelegatesTo(value=D, strategy=Closure.DELEGATE_FIRST) Closure<?> c) {\n" +
" new D().with(c)\n" +
" }\n" +
" }\n" +
" static class C implements I {\n" +
" @Delegate(parameterAnnotations=true) X x = new X()\n" + // generates m(Closure) that delegates to X#m(Closure)
" }\n" +
" static class D {\n" +
" void f() {\n" +
" print 'works'\n" +
" }\n" +
" }\n" +
" static main(args) {\n" +
" new C().m { f() }\n" +
" }\n" +
"}\n",
};
//@formatter:on

runConformTest(sources, "works");
}

@Test
public void testCompileStatic9938b() {
//@formatter:off
String[] sources = {
"Main.groovy",
"@groovy.transform.CompileStatic\n" +
"class Main {\n" +
" interface I {\n" +
" void m(@DelegatesTo(value=D, strategy=Closure.DELEGATE_FIRST) Closure<?> c)\n" +
" }\n" +
" trait T {\n" +
" void m(@DelegatesTo(value=D, strategy=Closure.DELEGATE_FIRST) Closure<?> c) {\n" +
" new D().with(c)\n" +
" }\n" +
" }\n" +
" static class C implements T {\n" + // generates m(Closure) that delegates to T$TraitHelper#m(Closure)
" }\n" +
" static class D {\n" +
" void f() {\n" +
" print 'works'\n" +
" }\n" +
" }\n" +
" static main(args) {\n" +
" new C().m { f() }\n" +
" }\n" +
"}\n",
};
//@formatter:on

runConformTest(sources, "works");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -326,6 +326,9 @@ private void addDelegateMethod(DelegateDescription delegate, List<MethodNode> ow
alsoLazy ? propX(varX("this"), delegate.name.substring(1)) : delegate.getOp,
candidate.getName(),
args);
// GRECLIPSE add -- GROOVY-9938
mce.setImplicitThis(false);
// GRECLIPSE end
mce.setSourcePosition(delegate.delegate);
ClassNode returnType = correctToGenericsSpecRecurse(genericsSpec, candidate.getReturnType(), currentMethodGenPlaceholders);
MethodNode newMethod = addGeneratedMethod(delegate.owner, candidate.getName(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -529,7 +529,7 @@ private static Statement createSuperFallback(MethodNode forwarderMethod, ClassNo
superCall.setImplicitThis(false);
CastExpression proxyReceiver = new CastExpression(Traits.GENERATED_PROXY_CLASSNODE, new VariableExpression("this"));
MethodCallExpression getProxy = new MethodCallExpression(proxyReceiver, "getProxyTarget", ArgumentListExpression.EMPTY_ARGUMENTS);
getProxy.setImplicitThis(true);
getProxy.setImplicitThis(false); // GRECLIPSE edit -- GROOVY-9938
StaticMethodCallExpression proxyCall = new StaticMethodCallExpression(
ClassHelper.make(InvokerHelper.class),
"invokeMethod",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -365,6 +365,9 @@ private void addDelegateMethod(DelegateDescription delegate, List<MethodNode> ow
alsoLazy ? propX(varX("this"), delegate.name.substring(1)) : delegate.getOp,
candidate.getName(),
args);
// GRECLIPSE add -- GROOVY-9938
mce.setImplicitThis(false);
// GRECLIPSE end
mce.setSourcePosition(delegate.delegate);
ClassNode returnType = correctToGenericsSpecRecurse(genericsSpec, candidate.getReturnType(), currentMethodGenPlaceholders);
MethodNode newMethod = addGeneratedMethod(delegate.owner, candidate.getName(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -520,7 +520,7 @@ private static Statement createSuperFallback(MethodNode forwarderMethod, ClassNo
superCall.setImplicitThis(false);
CastExpression proxyReceiver = new CastExpression(Traits.GENERATED_PROXY_CLASSNODE, new VariableExpression("this"));
MethodCallExpression getProxy = new MethodCallExpression(proxyReceiver, "getProxyTarget", ArgumentListExpression.EMPTY_ARGUMENTS);
getProxy.setImplicitThis(true);
getProxy.setImplicitThis(false); // GRECLIPSE edit -- GROOVY-9938
StaticMethodCallExpression proxyCall = new StaticMethodCallExpression(
ClassHelper.make(InvokerHelper.class),
"invokeMethod",
Expand Down
1 change: 1 addition & 0 deletions base/org.codehaus.groovy40/.checkstyle
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@
<file-match-pattern match-pattern="groovy/transform/ASTTestTransformation.groovy" include-pattern="false" />
<file-match-pattern match-pattern="groovy/transform/ASTTransformationCollectorCodeVisitor.java" include-pattern="false" />
<file-match-pattern match-pattern="groovy/transform/ASTTransformationVisitor.java" include-pattern="false" />
<file-match-pattern match-pattern="groovy/transform/DelegateASTTransformation.java" include-pattern="false" />
<file-match-pattern match-pattern="groovy/transform/FieldASTTransformation.java" include-pattern="false" />
<file-match-pattern match-pattern="groovy/transform/LogASTTransformation.java" include-pattern="false" />
<file-match-pattern match-pattern="groovy/transform/NotYetImplemented.java" include-pattern="false" />
Expand Down
Loading

0 comments on commit ac96a1c

Please sign in to comment.