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.
23 lines
666 B
Kotlin
Vendored
23 lines
666 B
Kotlin
Vendored
// LANGUAGE_VERSION: 1.0
|
|
|
|
fun equals5(a: Any?, b: Any?) = if (a is Float && b is Float?) a == b else null!!
|
|
|
|
fun equals6(a: Any?, b: Any?) = if (a is Float? && b is Float) a == b else null!!
|
|
|
|
fun equals8(a: Any?, b: Any?) = if (a is Float? && b is Float?) a == b else null!!
|
|
|
|
|
|
fun box(): String {
|
|
if (!equals5(-0.0F, 0.0F)) return "fail 5"
|
|
if (!equals6(-0.0F, 0.0F)) return "fail 6"
|
|
|
|
if (!equals8(-0.0F, 0.0F)) return "fail 8"
|
|
if (!equals8(null, null)) return "fail 9"
|
|
if (equals8(null, 0.0F)) return "fail 10"
|
|
if (equals8(0.0F, null)) return "fail 11"
|
|
|
|
return "OK"
|
|
}
|
|
|
|
// 3 areEqual \(Ljava/lang/Object;Ljava/lang/Object;\)Z
|
|
// 3 areEqual |