Skip to content

Commit 6d200a4

Browse files
committed
GROOVY-10033, GROOVY-10047
1 parent 4c7d8ad commit 6d200a4

File tree

3 files changed

+70
-3
lines changed

3 files changed

+70
-3
lines changed

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

+44-1
Original file line numberDiff line numberDiff line change
@@ -4594,7 +4594,7 @@ public void testCompileStatic9340() {
45944594
" }\n" +
45954595
" @groovy.transform.CompileStatic\n" +
45964596
" void test() {\n" +
4597-
" java.util.function.Consumer<Main> consumer = main -> print 'works'\n" + // A transform used a generics containing ClassNode Main for the method ...
4597+
" java.util.function.Consumer<Main> consumer = main -> print('works')\n" + // A transform used a generics containing ClassNode Main for the method ...
45984598
" consumer.accept(this)\n" +
45994599
" }\n" +
46004600
"}\n",
@@ -6098,4 +6098,47 @@ public void testCompileStatic9973() {
60986098

60996099
runConformTest(sources, "123456123");
61006100
}
6101+
6102+
@Test
6103+
public void testCompileStatic10033() {
6104+
assumeTrue(isParrotParser());
6105+
6106+
//@formatter:off
6107+
String[] sources = {
6108+
"Main.groovy",
6109+
"@groovy.transform.CompileStatic\n" +
6110+
"class Main {\n" +
6111+
" Main(java.util.function.Function<Main,String> f) {" +
6112+
" print f.apply(this)\n" +
6113+
" }\n" +
6114+
" String m() { 'works' }\n" +
6115+
" static main(args) {\n" +
6116+
" new Main(Main::m)\n" +
6117+
" }\n" +
6118+
"}\n",
6119+
};
6120+
//@formatter:on
6121+
6122+
runConformTest(sources, "works");
6123+
}
6124+
6125+
@Test
6126+
public void testCompileStatic10047() {
6127+
assumeTrue(isParrotParser());
6128+
6129+
//@formatter:off
6130+
String[] sources = {
6131+
"Main.groovy",
6132+
"import static java.util.stream.Collectors.toMap\n" +
6133+
"import java.util.function.Function\n" +
6134+
"@groovy.transform.CompileStatic\n" +
6135+
"void test() {\n" +
6136+
" print(['a','bc','def'].stream().collect(toMap(Function.<String>identity(), String::length)))\n" +
6137+
"}\n" +
6138+
"test()\n",
6139+
};
6140+
//@formatter:on
6141+
6142+
runConformTest(sources, "[a:1, bc:2, def:3]");
6143+
}
61016144
}

base/org.codehaus.groovy30/src/org/codehaus/groovy/transform/stc/StaticTypeCheckingVisitor.java

+13-1
Original file line numberDiff line numberDiff line change
@@ -2887,6 +2887,11 @@ protected void visitMethodCallArguments(final ClassNode receiver, final Argument
28872887
if (nExpressions > 0 && expressions.get(0) instanceof MapExpression && params.length > 0) {
28882888
checkNamedParamsAnnotation(params[0], (MapExpression) expressions.get(0));
28892889
}
2890+
// GRECLIPSE add -- GROOVY-10033, GROOVY-10047
2891+
if (visitClosures) {
2892+
inferMethodReferenceType(receiver, arguments, selectedMethod);
2893+
}
2894+
// GRECLIPSE end
28902895
}
28912896

28922897
private void checkNamedParamsAnnotation(final Parameter param, final MapExpression args) {
@@ -3743,8 +3748,9 @@ && isNumberType(getType(argumentList.getExpression(0)))) {
37433748
}
37443749
}
37453750
}
3746-
3751+
/* GRECLIPSE edit -- GROOVY-10033, GROOVY-10047
37473752
inferMethodReferenceType(call, receiver, argumentList);
3753+
*/
37483754
} finally {
37493755
typeCheckingContext.popEnclosingMethodCall();
37503756
extension.afterMethodCall(call);
@@ -3762,8 +3768,12 @@ private int getResolveStrategy(final Parameter parameter) {
37623768
return Closure.OWNER_FIRST;
37633769
}
37643770

3771+
/* GRECLIPSE edit -- GROOVY-10033, GROOVY-10047
37653772
private void inferMethodReferenceType(final MethodCallExpression call, final ClassNode receiver, final ArgumentListExpression argumentList) {
37663773
if (call == null) return;
3774+
*/
3775+
private void inferMethodReferenceType(final ClassNode receiver, final ArgumentListExpression argumentList, final MethodNode selectedMethod) {
3776+
// GRECLISPE end
37673777
if (receiver == null) return;
37683778
if (argumentList == null) return;
37693779

@@ -3775,7 +3785,9 @@ private void inferMethodReferenceType(final MethodCallExpression call, final Cla
37753785
return;
37763786
}
37773787

3788+
/* GRECLIPSE edit -- GROOVY-10033, GROOVY-10047
37783789
MethodNode selectedMethod = call.getNodeMetaData(DIRECT_METHOD_CALL_TARGET);
3790+
*/
37793791
if (selectedMethod == null) return;
37803792

37813793
Parameter[] parameters = selectedMethod.getParameters();

base/org.codehaus.groovy40/src/org/codehaus/groovy/transform/stc/StaticTypeCheckingVisitor.java

+13-1
Original file line numberDiff line numberDiff line change
@@ -2801,6 +2801,11 @@ protected void visitMethodCallArguments(final ClassNode receiver, final Argument
28012801
if (nExpressions > 0 && expressions.get(0) instanceof MapExpression && params.length > 0) {
28022802
checkNamedParamsAnnotation(params[0], (MapExpression) expressions.get(0));
28032803
}
2804+
// GRECLIPSE add -- GROOVY-10033, GROOVY-10047
2805+
if (visitClosures) {
2806+
inferMethodReferenceType(receiver, arguments, selectedMethod);
2807+
}
2808+
// GRECLIPSE end
28042809
}
28052810

28062811
private void checkNamedParamsAnnotation(final Parameter param, final MapExpression args) {
@@ -3643,8 +3648,9 @@ && isNumberType(getType(argumentList.getExpression(0)))) {
36433648
}
36443649
}
36453650
}
3646-
3651+
/* GRECLIPSE edit -- GROOVY-10033, GROOVY-10047
36473652
inferMethodReferenceType(call, receiver, argumentList);
3653+
*/
36483654
} finally {
36493655
typeCheckingContext.popEnclosingMethodCall();
36503656
extension.afterMethodCall(call);
@@ -3662,8 +3668,12 @@ private int getResolveStrategy(final Parameter parameter) {
36623668
return Closure.OWNER_FIRST;
36633669
}
36643670

3671+
/* GRECLIPSE edit -- GROOVY-10033, GROOVY-10047
36653672
private void inferMethodReferenceType(final MethodCallExpression call, final ClassNode receiver, final ArgumentListExpression argumentList) {
36663673
if (call == null) return;
3674+
*/
3675+
private void inferMethodReferenceType(final ClassNode receiver, final ArgumentListExpression argumentList, final MethodNode selectedMethod) {
3676+
// GRECLISPE end
36673677
if (receiver == null) return;
36683678
if (argumentList == null) return;
36693679

@@ -3675,7 +3685,9 @@ private void inferMethodReferenceType(final MethodCallExpression call, final Cla
36753685
return;
36763686
}
36773687

3688+
/* GRECLIPSE edit -- GROOVY-10033, GROOVY-10047
36783689
MethodNode selectedMethod = call.getNodeMetaData(DIRECT_METHOD_CALL_TARGET);
3690+
*/
36793691
if (selectedMethod == null) return;
36803692

36813693
Parameter[] parameters = selectedMethod.getParameters();

0 commit comments

Comments
 (0)