JVM IR: fix operand type for CompareTo intrinsic
It's incorrect to take the first parameter type from the expression itself because it can be nullable if smart casts are used. And if it's nullable, it's mapped to the wrapper type and calling `comparisonOperandType` for it makes no sense. Instead, take the type from the callee function, as it's guaranteed to be mapped to a JVM primitive type. E.g. in `test1` function in the added test, the problem was that the dispatch receiver type of the call expression is `Double?`, which is mapped to `java/lang/Double`, whereas we clearly wanted to obtain the primitive `D` (double) type. #KT-52163 Fixed
This commit is contained in:
@@ -0,0 +1,8 @@
|
||||
fun test(): Int {
|
||||
val d: Any?
|
||||
d = true
|
||||
return d.compareTo(false)
|
||||
}
|
||||
|
||||
fun box(): String =
|
||||
if (test() == 1) "OK" else "Fail"
|
||||
@@ -0,0 +1,17 @@
|
||||
fun test1(): Int {
|
||||
val d: Double?
|
||||
d = 8.3
|
||||
return d.compareTo(8)
|
||||
}
|
||||
|
||||
fun test2(): Int {
|
||||
val d: Double
|
||||
d = 8.3
|
||||
return d.compareTo(8)
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
if (test1() != 1) return "Fail test1"
|
||||
if (test2() != 1) return "Fail test2"
|
||||
return "OK"
|
||||
}
|
||||
Reference in New Issue
Block a user