KT-6136 VerifyError on data class inheriting from trait
- coerce property values to proper data class component types - add tests #KT-6136 Fixed
This commit is contained in:
+26
@@ -0,0 +1,26 @@
|
||||
trait Id<T> {
|
||||
val id: T
|
||||
}
|
||||
|
||||
open data class Actor (
|
||||
override val id: Int,
|
||||
val firstName: String,
|
||||
val lastName: String
|
||||
) : Id<Int>
|
||||
|
||||
fun box(): String {
|
||||
val a1 = Actor(1, "Jeff", "Bridges")
|
||||
|
||||
val a1c = a1.copy()
|
||||
if (a1c.id != a1.id) return "Failed: a1.copy().id==${a1c.id}"
|
||||
|
||||
val a2 = Actor(2, "Jeff", "Bridges")
|
||||
if (a2 == a1) return "Failed: a2==a1"
|
||||
|
||||
// Assume that our hashCode is good enough for this test :)
|
||||
if (a2.hashCode() == a1.hashCode()) return "Failed: a2.hashCode()==a1.hashCode()"
|
||||
|
||||
a1.toString()
|
||||
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
interface Id<T> {
|
||||
val id: T
|
||||
}
|
||||
|
||||
open data class Actor (
|
||||
id: Int,
|
||||
val firstName: String,
|
||||
val lastName: String
|
||||
) : Id<Int> {
|
||||
override val id: Int = id
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
val a1 = Actor(1, "Jeff", "Bridges")
|
||||
val a1copy = a1.copy(id = a1.id)
|
||||
|
||||
if (a1copy.id != a1.id) return "Failed: a1copy.id==${a1copy.id}"
|
||||
|
||||
return "OK"
|
||||
}
|
||||
Reference in New Issue
Block a user