Files
kotlin-fork/compiler/testData/diagnostics/tests/valueClasses/reservedMembersAndConstructsInsideValueClass.kt
T
vladislav.grechko e0c8142106 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
2022-10-10 16:52:34 +00:00

57 lines
1.6 KiB
Kotlin
Vendored

// !SKIP_JAVAC
// !LANGUAGE: +InlineClasses, +CustomEqualsInInlineClasses
// ALLOW_KOTLIN_PACKAGE
// !DIAGNOSTICS: -UNUSED_PARAMETER
package kotlin.jvm
annotation class JvmInline
@JvmInline
value class IC1(val x: Any) {
fun <!RESERVED_MEMBER_INSIDE_VALUE_CLASS!>box<!>() {}
fun <!RESERVED_MEMBER_INSIDE_VALUE_CLASS!>box<!>(x: Any) {}
fun <!RESERVED_MEMBER_INSIDE_VALUE_CLASS!>unbox<!>() {}
fun <!RESERVED_MEMBER_INSIDE_VALUE_CLASS!>unbox<!>(x: Any) {}
<!INEFFICIENT_EQUALS_OVERRIDING_IN_INLINE_CLASS!>override fun equals(other: Any?): Boolean<!> = true
override fun hashCode(): Int = 0
}
@JvmInline
value class IC2(val x: Any) {
fun <!RESERVED_MEMBER_INSIDE_VALUE_CLASS!>box<!>(x: Any) {}
fun <!RESERVED_MEMBER_INSIDE_VALUE_CLASS!>box<!>(): Any = TODO()
fun <!RESERVED_MEMBER_INSIDE_VALUE_CLASS!>unbox<!>(x: Any) {}
fun <!RESERVED_MEMBER_INSIDE_VALUE_CLASS!>unbox<!>(): Any = TODO()
fun equals(my: Any, other: Any): Boolean = true
fun hashCode(a: Any): Int = 0
}
@JvmInline
value class IC3(val x: Any) {
fun <!RESERVED_MEMBER_INSIDE_VALUE_CLASS!>box<!>(x: Any): Any = TODO()
fun <!RESERVED_MEMBER_INSIDE_VALUE_CLASS!>unbox<!>(x: Any): Any = TODO()
fun equals(): Boolean = true
}
interface WithBox {
fun box(): String
}
@JvmInline
value class IC4(val s: String) : WithBox {
override fun <!RESERVED_MEMBER_INSIDE_VALUE_CLASS!>box<!>(): String = ""
}
@JvmInline
value class IC5(val a: String) {
constructor(i: Int) : this(i.toString()) <!SECONDARY_CONSTRUCTOR_WITH_BODY_INSIDE_VALUE_CLASS!>{<!>
TODO("something")
}
}