Skip to content

Commit

Permalink
GROOVY-10107
Browse files Browse the repository at this point in the history
  • Loading branch information
eric-milles committed Jun 4, 2021
1 parent 6663f95 commit 848fd1c
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2941,6 +2941,24 @@ public void testTypeChecked10098() {
runConformTest(sources, "42");
}

@Test
public void testTypeChecked10107() {
//@formatter:off
String[] sources = {
"Main.groovy",
"@groovy.transform.TypeChecked\n" +
"class C<T extends Number> {\n" +
" void m() {\n" +
" T n = null\n" +
" }\n" +
"}\n" +
"new C<Long>().m()\n",
};
//@formatter:on

runConformTest(sources);
}

@Test
public void testTypeChecked10111() {
assumeTrue(isParrotParser());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -667,6 +667,12 @@ public static boolean checkCompatibleAssignmentTypes(final ClassNode left, final
* @see org.codehaus.groovy.runtime.typehandling.DefaultTypeTransformation#castToType(Object,Class)
*/
public static boolean checkCompatibleAssignmentTypes(final ClassNode left, final ClassNode right, final Expression rightExpression, final boolean allowConstructorCoercion) {
// GRECLIPSE add -- GROOVY-10107
boolean rightExpressionIsNull = isNullConstant(rightExpression);
if (rightExpressionIsNull && !isPrimitiveType(left)) {
return true;
}
// GRECLIPSE end
// GROOVY-7307, GROOVY-9952, et al.
if (left.isGenericsPlaceHolder()) {
GenericsType[] genericsTypes = left.getGenericsTypes();
Expand Down Expand Up @@ -704,13 +710,13 @@ public static boolean checkCompatibleAssignmentTypes(final ClassNode left, final
return WideningCategories.isBigIntCategory(getUnwrapper(rightRedirect)) || rightRedirect.isDerivedFrom(BigInteger_TYPE);
}
}

/* GRECLIPSE edit -- GROOVY-10107
// if rightExpression is null and leftExpression is not a primitive type, it's ok
boolean rightExpressionIsNull = isNullConstant(rightExpression);
if (rightExpressionIsNull && !isPrimitiveType(left)) {
return true;
}

*/
// anything can be assigned to an Object, String, Boolean or Class typed variable
if (isWildcardLeftHandSide(left) && !(leftRedirect == boolean_TYPE && rightExpressionIsNull)) return true;

Expand Down

0 comments on commit 848fd1c

Please sign in to comment.