Skip to content

Commit 848fd1c

Browse files
committed
GROOVY-10107
1 parent 6663f95 commit 848fd1c

2 files changed

Lines changed: 26 additions & 2 deletions

File tree

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

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2941,6 +2941,24 @@ public void testTypeChecked10098() {
29412941
runConformTest(sources, "42");
29422942
}
29432943

2944+
@Test
2945+
public void testTypeChecked10107() {
2946+
//@formatter:off
2947+
String[] sources = {
2948+
"Main.groovy",
2949+
"@groovy.transform.TypeChecked\n" +
2950+
"class C<T extends Number> {\n" +
2951+
" void m() {\n" +
2952+
" T n = null\n" +
2953+
" }\n" +
2954+
"}\n" +
2955+
"new C<Long>().m()\n",
2956+
};
2957+
//@formatter:on
2958+
2959+
runConformTest(sources);
2960+
}
2961+
29442962
@Test
29452963
public void testTypeChecked10111() {
29462964
assumeTrue(isParrotParser());

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

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -667,6 +667,12 @@ public static boolean checkCompatibleAssignmentTypes(final ClassNode left, final
667667
* @see org.codehaus.groovy.runtime.typehandling.DefaultTypeTransformation#castToType(Object,Class)
668668
*/
669669
public static boolean checkCompatibleAssignmentTypes(final ClassNode left, final ClassNode right, final Expression rightExpression, final boolean allowConstructorCoercion) {
670+
// GRECLIPSE add -- GROOVY-10107
671+
boolean rightExpressionIsNull = isNullConstant(rightExpression);
672+
if (rightExpressionIsNull && !isPrimitiveType(left)) {
673+
return true;
674+
}
675+
// GRECLIPSE end
670676
// GROOVY-7307, GROOVY-9952, et al.
671677
if (left.isGenericsPlaceHolder()) {
672678
GenericsType[] genericsTypes = left.getGenericsTypes();
@@ -704,13 +710,13 @@ public static boolean checkCompatibleAssignmentTypes(final ClassNode left, final
704710
return WideningCategories.isBigIntCategory(getUnwrapper(rightRedirect)) || rightRedirect.isDerivedFrom(BigInteger_TYPE);
705711
}
706712
}
707-
713+
/* GRECLIPSE edit -- GROOVY-10107
708714
// if rightExpression is null and leftExpression is not a primitive type, it's ok
709715
boolean rightExpressionIsNull = isNullConstant(rightExpression);
710716
if (rightExpressionIsNull && !isPrimitiveType(left)) {
711717
return true;
712718
}
713-
719+
*/
714720
// anything can be assigned to an Object, String, Boolean or Class typed variable
715721
if (isWildcardLeftHandSide(left) && !(leftRedirect == boolean_TYPE && rightExpressionIsNull)) return true;
716722

0 commit comments

Comments
 (0)