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,16 @@
abstract class Base {
final override fun equals(other: Any?) = false
final override fun hashCode() = 42
open override fun toString() = "OK"
}
data class Data1(val field: String) : Base()
interface AbstractAnyMembers {
abstract override fun equals(other: Any?): Boolean
abstract override fun hashCode(): Int
abstract override fun toString(): String
}
data class Data2(val field: String): Base(), AbstractAnyMembers
@@ -0,0 +1,34 @@
package
public interface AbstractAnyMembers {
public abstract override /*1*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
public abstract override /*1*/ fun hashCode(): kotlin.Int
public abstract override /*1*/ fun toString(): kotlin.String
}
public abstract class Base {
public constructor Base()
public final override /*1*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
public final override /*1*/ fun hashCode(): kotlin.Int
public open override /*1*/ fun toString(): kotlin.String
}
public final data class Data1 : Base {
public constructor Data1(/*0*/ field: kotlin.String)
public final val field: kotlin.String
public final operator /*synthesized*/ fun component1(): kotlin.String
public final /*synthesized*/ fun copy(/*0*/ field: kotlin.String = ...): Data1
public final override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
public final override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
public open override /*1*/ /*synthesized*/ fun toString(): kotlin.String
}
public final data class Data2 : Base, AbstractAnyMembers {
public constructor Data2(/*0*/ field: kotlin.String)
public final val field: kotlin.String
public final operator /*synthesized*/ fun component1(): kotlin.String
public final /*synthesized*/ fun copy(/*0*/ field: kotlin.String = ...): Data2
public final override /*2*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
public final override /*2*/ /*fake_override*/ fun hashCode(): kotlin.Int
public open override /*2*/ /*synthesized*/ fun toString(): kotlin.String
}
@@ -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
}
@@ -0,0 +1,48 @@
package
public interface Foo {
public abstract override /*1*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
public abstract override /*1*/ fun hashCode(): kotlin.Int
public abstract override /*1*/ fun toString(): kotlin.String
}
public final data class FooImpl : Foo {
public constructor FooImpl(/*0*/ num: kotlin.Int)
public final val num: kotlin.Int
public final operator /*synthesized*/ fun component1(): kotlin.Int
public final /*synthesized*/ fun copy(/*0*/ num: kotlin.Int = ...): FooImpl
public open override /*1*/ /*synthesized*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
public open override /*1*/ /*synthesized*/ fun hashCode(): kotlin.Int
public open override /*1*/ /*synthesized*/ fun toString(): kotlin.String
}
public final data class FooImplAll : Foo {
public constructor FooImplAll(/*0*/ num: kotlin.Int)
public final val num: kotlin.Int
public final operator /*synthesized*/ fun component1(): kotlin.Int
public final /*synthesized*/ fun copy(/*0*/ num: kotlin.Int = ...): FooImplAll
public open override /*1*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
public open override /*1*/ fun hashCode(): kotlin.Int
public open override /*1*/ fun toString(): kotlin.String
}
public final data class FooImplSome : Foo {
public constructor FooImplSome(/*0*/ num: kotlin.Int)
public final val num: kotlin.Int
public final operator /*synthesized*/ fun component1(): kotlin.Int
public final /*synthesized*/ fun copy(/*0*/ num: kotlin.Int = ...): FooImplSome
public open override /*1*/ /*synthesized*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
public open override /*1*/ fun hashCode(): kotlin.Int
public open override /*1*/ /*synthesized*/ fun toString(): kotlin.String
}
public final data class WrongSignatures : Foo {
public constructor WrongSignatures(/*0*/ num: kotlin.Int)
public final val num: kotlin.Int
public final operator /*synthesized*/ fun component1(): kotlin.Int
public final /*synthesized*/ fun copy(/*0*/ num: kotlin.Int = ...): WrongSignatures
public open fun equals(/*0*/ other: WrongSignatures): kotlin.Boolean
public open override /*1*/ /*synthesized*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
public open override /*1*/ fun hashCode(): kotlin.Boolean
public open override /*1*/ /*synthesized*/ fun toString(): kotlin.String
}