Support of custom 'equals' and 'hashCode' in inline classes
'equals' from any made available for overriding in inline classes 'typed' equals made available for definition in inline classes 'typed' equals definition made compulsory if 'untyped' is overridden 'operator' keyword is allowed in 'typed' equals definition ^KT-24874: Fixed
This commit is contained in:
committed by
teamcity
parent
527e8dde27
commit
e0c8142106
@@ -0,0 +1,35 @@
|
||||
// WITH_STDLIB
|
||||
// WORKS_WHEN_VALUE_CLASS
|
||||
// LANGUAGE: +ValueClasses, +CustomEqualsInInlineClasses
|
||||
// TARGET_BACKEND: JVM_IR
|
||||
|
||||
import kotlin.math.abs
|
||||
|
||||
OPTIONAL_JVM_INLINE_ANNOTATION
|
||||
value class IC1(val value: Double) {
|
||||
fun equals(other: IC1): Boolean {
|
||||
return abs(value - other.value) < 0.1
|
||||
}
|
||||
}
|
||||
|
||||
interface I {
|
||||
fun equals(param: IC2): Boolean
|
||||
}
|
||||
|
||||
OPTIONAL_JVM_INLINE_ANNOTATION
|
||||
value class IC2(val value: Int) : I {
|
||||
override fun equals(param: IC2): Boolean {
|
||||
return abs(value - param.value) < 2
|
||||
}
|
||||
}
|
||||
|
||||
OPTIONAL_JVM_INLINE_ANNOTATION
|
||||
value class IC3(val value: Int) {
|
||||
|
||||
}
|
||||
|
||||
fun box() =
|
||||
if (IC1(1.0) == IC1(1.05) && IC1(1.0) != IC1(1.2)
|
||||
&& IC2(5) == IC2(6) && IC2(5) != IC2(7)
|
||||
&& IC3(5) == IC3(5) && IC3(5) != IC3(6)
|
||||
&& IC1(1.0) != Any()) "OK" else "Fail"
|
||||
Reference in New Issue
Block a user