mirror of
https://github.com/jlengrand/kotlin.git
synced 2026-05-08 15:53:19 +00:00
NB we use 'Intrinsics.areEqual(Double, Double)' and
'Intrinsics.areEqual(Float, Float)', because right now we take
nullability from the inferred type of the expression (which is 'Any?' in
the test cases).
We should probably reconsider this in case of more exact information
available from the data flow analysis, e.g., in case of
fun test(x: Any?) =
x is Serializable && x is Double? && x == 0.0
We statically know that 'x' is not null in 'x == 0.0' (although it's
neither nullability of it's numeric type 'Double?' nor the nullability
of the inferred type 'Any?').
There might be some edge effects in the performance related to byte code
size and preventive unboxing and so on.
31 lines
704 B
Kotlin
Vendored
31 lines
704 B
Kotlin
Vendored
// LANGUAGE_VERSION: 1.0
|
|
fun box(): String {
|
|
val nullValue: Any? = null
|
|
val nullDouble: Double? = null
|
|
val minusZero: Any = -0.0
|
|
if (nullValue is Double?) {
|
|
when (nullValue) {
|
|
-0.0 -> {
|
|
return "fail 1"
|
|
}
|
|
nullDouble -> {}
|
|
else -> return "fail 2"
|
|
}
|
|
|
|
if (minusZero is Double) {
|
|
when (nullValue) {
|
|
minusZero -> {
|
|
return "fail 3"
|
|
}
|
|
nullDouble -> {
|
|
}
|
|
else -> return "fail 4"
|
|
}
|
|
}
|
|
|
|
}
|
|
return "OK"
|
|
}
|
|
// 4 areEqual \(Ljava/lang/Object;Ljava/lang/Object;\)Z
|
|
// 4 areEqual
|