Fixes to handling of boxed types
Boxed types and primitive types should cooperate properly now with primitive types in all basic cases. Added tests that verify this.
This commit is contained in:
committed by
Pavel V. Talanov
parent
60360cf22f
commit
e1d7c9d42c
@@ -496,6 +496,11 @@ public open class Converter() {
|
||||
if (isPrimitiveTypeOrNull && expression.isNullable()) {
|
||||
expression = BangBangExpression(expression)
|
||||
}
|
||||
else if (expectedType is PsiPrimitiveType && actualType is PsiClassType) {
|
||||
if (PsiPrimitiveType.getUnboxedType(actualType) == expectedType) {
|
||||
expression = BangBangExpression(expression)
|
||||
}
|
||||
}
|
||||
|
||||
if (actualType != null) {
|
||||
if (isConversionNeeded(actualType, expectedType) && !(expression is LiteralExpression))
|
||||
|
||||
@@ -49,7 +49,7 @@ public open class ExpressionVisitor(converter: Converter): StatementVisitor(conv
|
||||
}
|
||||
|
||||
val lhs = getConverter().expressionToExpression(expression?.getLExpression()!!)
|
||||
val rhs = getConverter().expressionToExpression(expression?.getRExpression()!!, expression?.getRExpression()?.getType())
|
||||
val rhs = getConverter().expressionToExpression(expression?.getRExpression()!!, expression?.getLExpression()?.getType())
|
||||
if (!secondOp.isEmpty()) {
|
||||
myResult = AssignmentExpression(lhs, BinaryExpression(lhs, rhs, secondOp), "=")
|
||||
}
|
||||
|
||||
@@ -0,0 +1,14 @@
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
class Boxing {
|
||||
void test() {
|
||||
Integer i = 0;
|
||||
Number n = 0.0f;
|
||||
i = 1;
|
||||
int j = i;
|
||||
Integer k = i+2;
|
||||
i = null;
|
||||
j = i;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
import java.util.ArrayList
|
||||
open class Boxing() {
|
||||
open fun test() : Unit {
|
||||
var i : Int? = 0
|
||||
var n : Number? = 0.0.toFloat()
|
||||
i = 1
|
||||
var j : Int = i!!
|
||||
var k : Int? = i!! + 2
|
||||
i = null
|
||||
j = i!!
|
||||
}
|
||||
}
|
||||
@@ -4,6 +4,6 @@ open class Test() {
|
||||
open fun test() : Unit {
|
||||
var i : Int? = 10
|
||||
var j : Int? = 10
|
||||
System.out?.println(i + j)
|
||||
System.out?.println(i!! + j!!)
|
||||
}
|
||||
}
|
||||
@@ -4,6 +4,6 @@ open fun getInteger(i : Int?) : Int? {
|
||||
return i
|
||||
}
|
||||
open fun test() : Unit {
|
||||
var i : Int = getInteger(10)
|
||||
var i : Int = getInteger(10)!!
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user