Fix == for inline classes with boxes

TODO generalize code generating object vs primitive equality

 #KT-25914 Fixed
 #KT-25981 Fixed
 #KT-25983 Fixed
This commit is contained in:
Dmitry Petrov
2018-08-09 18:30:09 +03:00
parent cd12772bc5
commit 4f6aa50417
10 changed files with 225 additions and 29 deletions
@@ -0,0 +1,16 @@
// !LANGUAGE: +InlineClasses
// IGNORE_BACKEND: JVM_IR, JS_IR, JS
inline class InlineFloat(val data: Float)
inline class InlineDouble(val data: Double)
fun box(): String {
if (InlineFloat(0.0f) == InlineFloat(-0.0f)) throw AssertionError()
if (InlineFloat(Float.NaN) != InlineFloat(Float.NaN)) throw AssertionError()
if (InlineDouble(0.0) == InlineDouble(-0.0)) throw AssertionError()
if (InlineDouble(Double.NaN) != InlineDouble(Double.NaN)) throw AssertionError()
return "OK"
}
@@ -0,0 +1,14 @@
// !LANGUAGE: +InlineClasses
// IGNORE_BACKEND: JVM_IR
inline class Z(val data: Int) {
override fun equals(other: Any?): Boolean =
other is Z &&
data % 256 == other.data % 256
}
fun box(): String {
if (Z(0) != Z(256)) throw AssertionError()
return "OK"
}
@@ -0,0 +1,20 @@
// !LANGUAGE: +InlineClasses
// IGNORE_BACKEND: JVM_IR, JS_IR, JS
inline class Z(val value: Int)
fun eq(a: Z?, b: Z) = a == b
fun eqq(a: Z, b: Z?) = a == b
fun box(): String {
if (!eq(Z(1), Z(1))) throw AssertionError()
if (eq(Z(1), Z(2))) throw AssertionError()
if (eq(null, Z(0))) throw AssertionError()
if (!eqq(Z(1), Z(1))) throw AssertionError()
if (eqq(Z(1), Z(2))) throw AssertionError()
if (eqq(Z(0), null)) throw AssertionError()
return "OK"
}