Skip to content

Commit d0ef1fa

Browse files
committed
GROOVY-10254
1 parent 5deb971 commit d0ef1fa

File tree

4 files changed

+30
-0
lines changed

4 files changed

+30
-0
lines changed

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

+16
Original file line numberDiff line numberDiff line change
@@ -3635,4 +3635,20 @@ public void testTypeChecked10239a() {
36353635

36363636
runConformTest(sources, "2");
36373637
}
3638+
3639+
@Test
3640+
public void testTypeChecked10254() {
3641+
//@formatter:off
3642+
String[] sources = {
3643+
"Main.groovy",
3644+
"@groovy.transform.TypeChecked\n" +
3645+
"java.util.function.Supplier<Integer> test() {\n" +
3646+
" { -> 42 }\n" + // should coerce without "as Supplier<Integer>"
3647+
"}\n" +
3648+
"print(test().get())\n",
3649+
};
3650+
//@formatter:on
3651+
3652+
runConformTest(sources, "42");
3653+
}
36383654
}

base/org.codehaus.groovy25/src/org/codehaus/groovy/transform/stc/StaticTypeCheckingSupport.java

+5
Original file line numberDiff line numberDiff line change
@@ -802,6 +802,11 @@ public static boolean checkCompatibleAssignmentTypes(ClassNode left, ClassNode r
802802
if (leftRedirect.equals(GROOVY_OBJECT_TYPE) && isBeingCompiled(right)) {
803803
return true;
804804
}
805+
// GRECLIPSE add -- GROOVY-10254
806+
if (right.isDerivedFrom(CLOSURE_TYPE) && isSAMType(left)) {
807+
return true;
808+
}
809+
// GRECLIPSE end
805810

806811
if (left.isGenericsPlaceHolder()) {
807812
// GROOVY-7307

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

+5
Original file line numberDiff line numberDiff line change
@@ -753,6 +753,11 @@ public static boolean checkCompatibleAssignmentTypes(final ClassNode left, final
753753
if (GROOVY_OBJECT_TYPE.equals(leftRedirect) && isBeingCompiled(right)) {
754754
return true;
755755
}
756+
// GRECLIPSE add -- GROOVY-10254
757+
if (right.isDerivedFrom(CLOSURE_TYPE) && isSAMType(left)) {
758+
return true;
759+
}
760+
// GRECLIPSE end
756761

757762
if (left.isGenericsPlaceHolder()) {
758763
// GROOVY-7307

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

+4
Original file line numberDiff line numberDiff line change
@@ -745,6 +745,10 @@ public static boolean checkCompatibleAssignmentTypes(final ClassNode left, final
745745
if (isGroovyObjectType(leftRedirect) && isBeingCompiled(right)) {
746746
return true;
747747
}
748+
// GRECLIPSE add -- GROOVY-10254
749+
if (right.isDerivedFrom(CLOSURE_TYPE) && isSAMType(left)) {
750+
return true;
751+
}
748752

749753
/* GRECLIPSE edit -- GROOVY-7307, GROOVY-7316, GROOVY-10256
750754
return right.isGenericsPlaceHolder();

0 commit comments

Comments
 (0)