Skip to content

Commit 6456b23

Browse files
committed
GROOVY-9790
1 parent 469a54a commit 6456b23

File tree

3 files changed

+32
-25
lines changed

3 files changed

+32
-25
lines changed

base-test/org.eclipse.jdt.groovy.core.tests.compiler/src/org/eclipse/jdt/groovy/core/tests/basic/GroovySimpleTests.java

-23
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@
2525
import java.io.File;
2626
import java.util.Iterator;
2727
import java.util.Map;
28-
import java.util.stream.Stream;
2928

3029
import org.codehaus.jdt.groovy.internal.compiler.ast.EventListener;
3130
import org.codehaus.jdt.groovy.internal.compiler.ast.GroovyClassScope;
@@ -598,28 +597,6 @@ public void testLambdaScope2() {
598597
runConformTest(sources, "0f1f2f3f4f");
599598
}
600599

601-
@Test // GROOVY-9790
602-
public void testLambdaTypes1() {
603-
assumeTrue(isParrotParser());
604-
605-
for (Object sig : Stream.of("i", "(int i)", "(Integer i)").skip(isAtLeastGroovy(40) ? 0 : 1).toArray()) { // bare name not supported until Groovy 3.0.10
606-
//@formatter:off
607-
String[] sources = {
608-
"Script.groovy",
609-
"@groovy.transform.CompileStatic\n" +
610-
"void test() {\n" +
611-
" java.util.stream.IntStream.range(0, 2).forEach(\n" +
612-
" " + sig + " -> { assert i >= 0 && i < 2 }\n" +
613-
" )\n" +
614-
"}\n" +
615-
"test()\n",
616-
};
617-
//@formatter:on
618-
619-
runConformTest(sources);
620-
}
621-
}
622-
623600
@Test
624601
public void testMultiCatch() {
625602
//@formatter:off

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

+22
Original file line numberDiff line numberDiff line change
@@ -6158,6 +6158,28 @@ public void testCompileStatic9786() {
61586158
runConformTest(sources, "B");
61596159
}
61606160

6161+
@Test
6162+
public void testCompileStatic9790() {
6163+
assumeTrue(isParrotParser());
6164+
6165+
for (Object sig : new String[] {"i", "(int i)", "(Integer i)"}) {
6166+
//@formatter:off
6167+
String[] sources = {
6168+
"Script.groovy",
6169+
"@groovy.transform.CompileStatic\n" +
6170+
"void test() {\n" +
6171+
" java.util.stream.IntStream.range(0, 2).forEach(\n" +
6172+
" " + sig + " -> { assert i >= 0 && i < 2 }\n" +
6173+
" )\n" +
6174+
"}\n" +
6175+
"test()\n",
6176+
};
6177+
//@formatter:on
6178+
6179+
runConformTest(sources);
6180+
}
6181+
}
6182+
61616183
@Test
61626184
public void testCompileStatic9799() {
61636185
assumeTrue(isParrotParser());

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

+10-2
Original file line numberDiff line numberDiff line change
@@ -3358,8 +3358,16 @@ protected void inferClosureParameterTypes(final ClassNode receiver, final Expres
33583358
paramTypes = samParamTypes;
33593359
} else {
33603360
paramTypes = new ClassNode[n];
3361-
for (int i = 0; i < n; i += 1) {
3362-
paramTypes[i] = !p[i].isDynamicTyped() ? p[i].getOriginType() : (i < samParamTypes.length ? samParamTypes[i] : null);
3361+
for (int i = 0; i < n && i < samParamTypes.length; i += 1) {
3362+
if (p[i].isDynamicTyped()) {
3363+
paramTypes[i] = samParamTypes[i];
3364+
} else {
3365+
ClassNode declared = p[i].getOriginType(), inferred = samParamTypes[i];
3366+
if (isPrimitiveType(inferred) && getWrapper(inferred).equals(declared))
3367+
paramTypes[i] = inferred; // GROOVY-9790
3368+
else
3369+
paramTypes[i] = declared;
3370+
}
33633371
}
33643372
}
33653373
expression.putNodeMetaData(CLOSURE_ARGUMENTS, paramTypes);

0 commit comments

Comments
 (0)