KT-15871 Unnecessary boxing for equality operator on inlined primitive values
Allow kotlin.jvm.internal.Intrinsics#areEqual for boxed values. Rewrite to primitive equality. NB we can't do that for Float and Double, because java.lang.Float#equals and java.lang.Double#equals behave differently from primitive equality comparisons.
This commit is contained in:
@@ -0,0 +1,8 @@
|
||||
// IGNORE_BACKEND: JS
|
||||
|
||||
fun equals1(a: Double, b: Double) = a.equals(b)
|
||||
|
||||
fun box(): String {
|
||||
if ((-0.0).equals(0.0)) return "fail 0"
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
fun box() =
|
||||
if (getAndCheck({ 42 }, { 42 })) "OK" else "fail"
|
||||
|
||||
inline fun <T> getAndCheck(getFirst: () -> T, getSecond: () -> T) =
|
||||
getFirst() == getSecond()
|
||||
+6
-1
@@ -2,6 +2,9 @@
|
||||
fun box(): String {
|
||||
val plusZero: Double? = 0.0
|
||||
val minusZero: Double = -0.0
|
||||
|
||||
useBoxed(plusZero)
|
||||
|
||||
if (plusZero?.equals(minusZero) ?: null!!) {
|
||||
return "fail 1"
|
||||
}
|
||||
@@ -11,4 +14,6 @@ fun box(): String {
|
||||
}
|
||||
|
||||
return "OK"
|
||||
}
|
||||
}
|
||||
|
||||
fun useBoxed(a: Any?) {}
|
||||
@@ -0,0 +1,17 @@
|
||||
// https://youtrack.jetbrains.com/issue/KT-15871
|
||||
|
||||
// FILE: Test.kt
|
||||
|
||||
fun getAndCheckInt(a: Int, b: Int) =
|
||||
getAndCheck({ a }, { b })
|
||||
|
||||
// @TestKt.class:
|
||||
// 0 valueOf
|
||||
// 0 Value
|
||||
// 0 areEqual
|
||||
|
||||
// FILE: Inline.kt
|
||||
inline fun <T> getAndCheck(getFirst: () -> T, getSecond: () -> T) =
|
||||
getFirst() == getSecond()
|
||||
|
||||
|
||||
+5
@@ -0,0 +1,5 @@
|
||||
@kotlin.Metadata
|
||||
public final class ExplicitEqualsOnDoubleKt {
|
||||
public final static @org.jetbrains.annotations.NotNull method box(): java.lang.String
|
||||
public final static method equals1(p0: double, p1: double): boolean
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
@kotlin.Metadata
|
||||
public final class Kt15871Kt {
|
||||
public final static @org.jetbrains.annotations.NotNull method box(): java.lang.String
|
||||
public final static method getAndCheck(@org.jetbrains.annotations.NotNull p0: kotlin.jvm.functions.Function0, @org.jetbrains.annotations.NotNull p1: kotlin.jvm.functions.Function0): boolean
|
||||
}
|
||||
@@ -1,4 +1,5 @@
|
||||
@kotlin.Metadata
|
||||
public final class SafeCallKt {
|
||||
public final static @org.jetbrains.annotations.NotNull method box(): java.lang.String
|
||||
public final static method useBoxed(@org.jetbrains.annotations.Nullable p0: java.lang.Object): void
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user