Allow data classes to implement equals/hashCode/toString from base classes

#KT-11306 Fixed
This commit is contained in:
Alexander Udalov
2016-09-14 13:18:09 +03:00
parent 98f6ea577a
commit fea116f14e
10 changed files with 205 additions and 11 deletions
@@ -0,0 +1,25 @@
// KT-11306 ABSTRACT_MEMBER_NOT_IMPLEMENTED for data class should inheriting interfaces requiring equals(), hashCode(), or toString()
interface Foo {
override fun equals(other: Any?): Boolean
override fun hashCode(): Int
override fun toString(): String
}
data class FooImpl(val num: Int) : Foo
data class FooImplSome(val num: Int) : Foo {
override fun hashCode() = 42
}
data class FooImplAll(val num: Int) : Foo {
override fun equals(other: Any?) = false
override fun hashCode() = 42
override fun toString() = "OK"
}
data class WrongSignatures(val num: Int) : Foo {
<!NOTHING_TO_OVERRIDE!>override<!> fun equals(other: WrongSignatures) = false
override fun hashCode(): <!RETURN_TYPE_MISMATCH_ON_OVERRIDE!>Boolean<!> = true
}