JVM IR: Avoid optimizing comparisons between boxed primitives and null
A comparison of the form `x == null` where `x` is of type `Int` might not be vacuous if `x` is a boxed value coming from Java code.
This commit is contained in:
committed by
Dmitry Petrov
parent
32e1ec8e98
commit
4b954c347a
@@ -1,6 +1,5 @@
|
||||
// IGNORE_BACKEND_FIR: JVM_IR
|
||||
// TARGET_BACKEND: JVM
|
||||
// IGNORE_BACKEND: JVM_IR
|
||||
// FILE: Unsound.java
|
||||
|
||||
import test.Wrap;
|
||||
@@ -17,6 +16,4 @@ package test
|
||||
|
||||
class Wrap<T>(val x: T)
|
||||
|
||||
// JVM IR generates bytecode that fails with NPE because it unwraps the value with `Number.intValue()`,
|
||||
// whereas JVM generates a simple null check without unwrapping the box.
|
||||
fun box(): String = if ((Unsound.get<Int>() as Wrap<Int>).x == null) "OK" else "Fail"
|
||||
|
||||
Reference in New Issue
Block a user