Files
kotlin-fork/compiler/testData/diagnostics/tests/inlineClasses/inefficientEqualsOverridingInInlineClass.kt
T
vladislav.grechko 36b8ba8df3 Improve support of custom equals in inline classes
- Ensure that typed equals parameter's type is a star projection of
  corresponding inline class

- Make possible to declare typed equals that returns 'Nothing'

- Forbid type parameters in typed equals operator declaration

^KT-54909 fixed
^KT-54910 fixed
2022-11-17 15:35:14 +01:00

37 lines
809 B
Kotlin
Vendored

// FIR_IDENTICAL
// WITH_STDLIB
// !DIAGNOSTICS: -DEBUG_INFO_SMARTCAST
// LANGUAGE: +CustomEqualsInInlineClasses
@JvmInline
value class IC1(val x: Int) {
override fun <!INEFFICIENT_EQUALS_OVERRIDING_IN_INLINE_CLASS!>equals<!>(other: Any?): Boolean {
if (other !is IC1) {
return false
}
return x == other.x
}
}
@JvmInline
value class IC2(val x: Int) {
override fun hashCode() = 0
}
@JvmInline
value class IC3(val x: Int) {
override fun equals(other: Any?) = true
operator fun equals(other: IC3) = true
override fun hashCode() = 0
}
@JvmInline
value class IC4<T>(val x: Int) {
override fun <!INEFFICIENT_EQUALS_OVERRIDING_IN_INLINE_CLASS!>equals<!>(other: Any?) = true
fun equals(other: IC4<T>) = true
override fun hashCode() = 0
}