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:
Alexander Udalov
2022-04-28 23:01:59 +02:00
parent f8ef028da3
commit 6d664bcd10
14 changed files with 151 additions and 12 deletions
@@ -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"
}