Skip to content

Commit ac96a1c

Browse files
committed
GROOVY-9938
1 parent d1022ea commit ac96a1c

8 files changed

Lines changed: 550 additions & 3 deletions

File tree

base-test/org.eclipse.jdt.groovy.core.tests.compiler/src/org/eclipse/jdt/groovy/core/tests/xform/StaticCompilationTests.java

Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5774,4 +5774,99 @@ public void testCompileStatic9918() {
57745774

57755775
runConformTest(sources, "");
57765776
}
5777+
5778+
@Test
5779+
public void testCompileStatic9938() {
5780+
//@formatter:off
5781+
String[] sources = {
5782+
"Main.groovy",
5783+
"@groovy.transform.CompileStatic\n" +
5784+
"class Main {\n" +
5785+
" interface I {\n" +
5786+
" void m(@DelegatesTo(value=D, strategy=Closure.DELEGATE_FIRST) Closure<?> c)\n" +
5787+
" }\n" +
5788+
" static class C implements I {\n" +
5789+
" void m(@DelegatesTo(value=D, strategy=Closure.DELEGATE_FIRST) Closure<?> c) {\n" +
5790+
" new D().with(c)\n" +
5791+
" }\n" +
5792+
" }\n" +
5793+
" static class D {\n" +
5794+
" void f() {\n" +
5795+
" print 'works'\n" +
5796+
" }\n" +
5797+
" }\n" +
5798+
" static main(args) {\n" +
5799+
" new C().m { f() }\n" +
5800+
" }\n" +
5801+
"}\n",
5802+
};
5803+
//@formatter:on
5804+
5805+
runConformTest(sources, "works");
5806+
}
5807+
5808+
@Test
5809+
public void testCompileStatic9938a() {
5810+
//@formatter:off
5811+
String[] sources = {
5812+
"Main.groovy",
5813+
"@groovy.transform.CompileStatic\n" +
5814+
"class Main {\n" +
5815+
" interface I {\n" +
5816+
" void m(@DelegatesTo(value=D, strategy=Closure.DELEGATE_FIRST) Closure<?> c)\n" +
5817+
" }\n" +
5818+
" static class X implements I {\n" +
5819+
" void m(@DelegatesTo(value=D, strategy=Closure.DELEGATE_FIRST) Closure<?> c) {\n" +
5820+
" new D().with(c)\n" +
5821+
" }\n" +
5822+
" }\n" +
5823+
" static class C implements I {\n" +
5824+
" @Delegate(parameterAnnotations=true) X x = new X()\n" + // generates m(Closure) that delegates to X#m(Closure)
5825+
" }\n" +
5826+
" static class D {\n" +
5827+
" void f() {\n" +
5828+
" print 'works'\n" +
5829+
" }\n" +
5830+
" }\n" +
5831+
" static main(args) {\n" +
5832+
" new C().m { f() }\n" +
5833+
" }\n" +
5834+
"}\n",
5835+
};
5836+
//@formatter:on
5837+
5838+
runConformTest(sources, "works");
5839+
}
5840+
5841+
@Test
5842+
public void testCompileStatic9938b() {
5843+
//@formatter:off
5844+
String[] sources = {
5845+
"Main.groovy",
5846+
"@groovy.transform.CompileStatic\n" +
5847+
"class Main {\n" +
5848+
" interface I {\n" +
5849+
" void m(@DelegatesTo(value=D, strategy=Closure.DELEGATE_FIRST) Closure<?> c)\n" +
5850+
" }\n" +
5851+
" trait T {\n" +
5852+
" void m(@DelegatesTo(value=D, strategy=Closure.DELEGATE_FIRST) Closure<?> c) {\n" +
5853+
" new D().with(c)\n" +
5854+
" }\n" +
5855+
" }\n" +
5856+
" static class C implements T {\n" + // generates m(Closure) that delegates to T$TraitHelper#m(Closure)
5857+
" }\n" +
5858+
" static class D {\n" +
5859+
" void f() {\n" +
5860+
" print 'works'\n" +
5861+
" }\n" +
5862+
" }\n" +
5863+
" static main(args) {\n" +
5864+
" new C().m { f() }\n" +
5865+
" }\n" +
5866+
"}\n",
5867+
};
5868+
//@formatter:on
5869+
5870+
runConformTest(sources, "works");
5871+
}
57775872
}

base/org.codehaus.groovy25/src/org/codehaus/groovy/transform/DelegateASTTransformation.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -326,6 +326,9 @@ private void addDelegateMethod(DelegateDescription delegate, List<MethodNode> ow
326326
alsoLazy ? propX(varX("this"), delegate.name.substring(1)) : delegate.getOp,
327327
candidate.getName(),
328328
args);
329+
// GRECLIPSE add -- GROOVY-9938
330+
mce.setImplicitThis(false);
331+
// GRECLIPSE end
329332
mce.setSourcePosition(delegate.delegate);
330333
ClassNode returnType = correctToGenericsSpecRecurse(genericsSpec, candidate.getReturnType(), currentMethodGenPlaceholders);
331334
MethodNode newMethod = addGeneratedMethod(delegate.owner, candidate.getName(),

base/org.codehaus.groovy25/src/org/codehaus/groovy/transform/trait/TraitComposer.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -529,7 +529,7 @@ private static Statement createSuperFallback(MethodNode forwarderMethod, ClassNo
529529
superCall.setImplicitThis(false);
530530
CastExpression proxyReceiver = new CastExpression(Traits.GENERATED_PROXY_CLASSNODE, new VariableExpression("this"));
531531
MethodCallExpression getProxy = new MethodCallExpression(proxyReceiver, "getProxyTarget", ArgumentListExpression.EMPTY_ARGUMENTS);
532-
getProxy.setImplicitThis(true);
532+
getProxy.setImplicitThis(false); // GRECLIPSE edit -- GROOVY-9938
533533
StaticMethodCallExpression proxyCall = new StaticMethodCallExpression(
534534
ClassHelper.make(InvokerHelper.class),
535535
"invokeMethod",

base/org.codehaus.groovy30/src/org/codehaus/groovy/transform/DelegateASTTransformation.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -365,6 +365,9 @@ private void addDelegateMethod(DelegateDescription delegate, List<MethodNode> ow
365365
alsoLazy ? propX(varX("this"), delegate.name.substring(1)) : delegate.getOp,
366366
candidate.getName(),
367367
args);
368+
// GRECLIPSE add -- GROOVY-9938
369+
mce.setImplicitThis(false);
370+
// GRECLIPSE end
368371
mce.setSourcePosition(delegate.delegate);
369372
ClassNode returnType = correctToGenericsSpecRecurse(genericsSpec, candidate.getReturnType(), currentMethodGenPlaceholders);
370373
MethodNode newMethod = addGeneratedMethod(delegate.owner, candidate.getName(),

base/org.codehaus.groovy30/src/org/codehaus/groovy/transform/trait/TraitComposer.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -520,7 +520,7 @@ private static Statement createSuperFallback(MethodNode forwarderMethod, ClassNo
520520
superCall.setImplicitThis(false);
521521
CastExpression proxyReceiver = new CastExpression(Traits.GENERATED_PROXY_CLASSNODE, new VariableExpression("this"));
522522
MethodCallExpression getProxy = new MethodCallExpression(proxyReceiver, "getProxyTarget", ArgumentListExpression.EMPTY_ARGUMENTS);
523-
getProxy.setImplicitThis(true);
523+
getProxy.setImplicitThis(false); // GRECLIPSE edit -- GROOVY-9938
524524
StaticMethodCallExpression proxyCall = new StaticMethodCallExpression(
525525
ClassHelper.make(InvokerHelper.class),
526526
"invokeMethod",

base/org.codehaus.groovy40/.checkstyle

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@
6262
<file-match-pattern match-pattern="groovy/transform/ASTTestTransformation.groovy" include-pattern="false" />
6363
<file-match-pattern match-pattern="groovy/transform/ASTTransformationCollectorCodeVisitor.java" include-pattern="false" />
6464
<file-match-pattern match-pattern="groovy/transform/ASTTransformationVisitor.java" include-pattern="false" />
65+
<file-match-pattern match-pattern="groovy/transform/DelegateASTTransformation.java" include-pattern="false" />
6566
<file-match-pattern match-pattern="groovy/transform/FieldASTTransformation.java" include-pattern="false" />
6667
<file-match-pattern match-pattern="groovy/transform/LogASTTransformation.java" include-pattern="false" />
6768
<file-match-pattern match-pattern="groovy/transform/NotYetImplemented.java" include-pattern="false" />

0 commit comments

Comments
 (0)