70
70
import static java .lang .Math .min ;
71
71
import static org .apache .groovy .ast .tools .ClassNodeUtils .addGeneratedMethod ;
72
72
import static org .apache .groovy .ast .tools .ClassNodeUtils .samePackageName ;
73
+ import static org .apache .groovy .ast .tools .ExpressionUtils .isNullConstant ;
73
74
import static org .codehaus .groovy .ast .ClassHelper .BigDecimal_TYPE ;
74
75
import static org .codehaus .groovy .ast .ClassHelper .BigInteger_TYPE ;
75
76
import static org .codehaus .groovy .ast .ClassHelper .Boolean_TYPE ;
84
85
import static org .codehaus .groovy .ast .ClassHelper .GSTRING_TYPE ;
85
86
import static org .codehaus .groovy .ast .ClassHelper .Integer_TYPE ;
86
87
import static org .codehaus .groovy .ast .ClassHelper .Long_TYPE ;
88
+ import static org .codehaus .groovy .ast .ClassHelper .Number_TYPE ;
87
89
import static org .codehaus .groovy .ast .ClassHelper .OBJECT_TYPE ;
88
90
import static org .codehaus .groovy .ast .ClassHelper .STRING_TYPE ;
89
91
import static org .codehaus .groovy .ast .ClassHelper .Short_TYPE ;
@@ -655,9 +657,9 @@ public static boolean checkCompatibleAssignmentTypes(final ClassNode left, final
655
657
return left == VOID_TYPE || left == void_WRAPPER_TYPE ;
656
658
}
657
659
658
- if (( isNumberType (rightRedirect ) || WideningCategories .isNumberCategory (rightRedirect ) )) {
659
- if (BigDecimal_TYPE == leftRedirect ) {
660
- // any number can be assigned to a big decimal
660
+ if (isNumberType (rightRedirect ) || WideningCategories .isNumberCategory (rightRedirect )) {
661
+ if (BigDecimal_TYPE == leftRedirect || Number_TYPE == leftRedirect ) {
662
+ // any number can be assigned to BigDecimal or Number
661
663
return true ;
662
664
}
663
665
if (BigInteger_TYPE == leftRedirect ) {
@@ -666,7 +668,7 @@ public static boolean checkCompatibleAssignmentTypes(final ClassNode left, final
666
668
}
667
669
668
670
// if rightExpression is null and leftExpression is not a primitive type, it's ok
669
- boolean rightExpressionIsNull = (rightExpression instanceof ConstantExpression && (( ConstantExpression ) rightExpression ). isNullExpression () );
671
+ boolean rightExpressionIsNull = isNullConstant (rightExpression );
670
672
if (rightExpressionIsNull && !isPrimitiveType (left )) {
671
673
return true ;
672
674
}
0 commit comments