KT-4107 Data objects

This commit is contained in:
Pavel Mikhailovskii
2022-06-28 09:51:57 +02:00
parent 6c31dc90e4
commit c3c09aa95a
75 changed files with 1183 additions and 134 deletions
@@ -0,0 +1,6 @@
// FIR_IDENTICAL
// LANGUAGE: +DataObjects
class C {
companion <!WRONG_MODIFIER_TARGET!>data<!> object Object
}
@@ -0,0 +1,16 @@
package
public final class C {
public constructor C()
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
public data companion object Object {
private constructor Object()
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
}
}
@@ -1,2 +0,0 @@
// FIR_IDENTICAL
<!WRONG_MODIFIER_TARGET!>data<!> object Object<!CONSTRUCTOR_IN_OBJECT!>(val x: Int, val y: Int)<!>
@@ -1,13 +0,0 @@
package
public data object Object {
private constructor Object(/*0*/ x: kotlin.Int, /*1*/ y: kotlin.Int)
public final val x: kotlin.Int
public final val y: kotlin.Int
public final operator /*synthesized*/ fun component1(): kotlin.Int
public final operator /*synthesized*/ fun component2(): kotlin.Int
public final /*synthesized*/ fun copy(/*0*/ x: kotlin.Int = ..., /*1*/ y: kotlin.Int = ...): Object
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
}
@@ -0,0 +1,2 @@
// LANGUAGE: -DataObjects
<!WRONG_MODIFIER_TARGET!>data<!> object Object
@@ -0,0 +1,2 @@
// LANGUAGE: -DataObjects
<!UNSUPPORTED_FEATURE!>data<!> object Object
@@ -0,0 +1,9 @@
package
public data object Object {
private constructor Object()
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
}
@@ -0,0 +1,3 @@
// LANGUAGE: +DataObjects
// FIR_IDENTICAL
data object Object
@@ -0,0 +1,9 @@
package
public data object Object {
private constructor Object()
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
}
@@ -0,0 +1,10 @@
// FIR_IDENTICAL
// LANGUAGE: +DataObjects
interface I {
fun foo()
}
val o = <!UNRESOLVED_REFERENCE!>data<!><!SYNTAX!><!> object<!SYNTAX!><!>: I {
override fun foo() {}
}
@@ -0,0 +1,18 @@
package
public val o: [Error type: Not found recorded type for data]
public object `<no name provided>` : I {
private constructor `<no name provided>`()
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
public open override /*1*/ fun foo(): kotlin.Unit
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
}
public interface I {
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
public abstract fun foo(): kotlin.Unit
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
}
+3 -3
View File
@@ -3,8 +3,8 @@
B(2)
}
<!WRONG_MODIFIER_TARGET!>data<!> object <!DATA_CLASS_WITHOUT_PARAMETERS!>Second<!>
<!UNSUPPORTED_FEATURE!>data<!> object Second
<!WRONG_MODIFIER_TARGET!>data<!> interface <!DATA_CLASS_WITHOUT_PARAMETERS!>Third<!>
<!WRONG_MODIFIER_TARGET!>data<!> interface Third
<!WRONG_MODIFIER_TARGET!>data<!> annotation class Fourth(val x: Int)
<!WRONG_MODIFIER_TARGET!>data<!> annotation class Fourth(val x: Int)
@@ -11,8 +11,6 @@ public final data enum class First : kotlin.Enum<First> {
public final val x: kotlin.Int
protected final override /*1*/ /*fake_override*/ fun clone(): kotlin.Any
public final override /*1*/ /*fake_override*/ fun compareTo(/*0*/ other: First): kotlin.Int
public final operator /*synthesized*/ fun component1(): kotlin.Int
public final /*synthesized*/ fun copy(/*0*/ x: kotlin.Int = ...): First
public final override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
protected/*protected and package*/ final override /*1*/ /*fake_override*/ /*isHiddenForResolutionEverywhereBesideSupercalls*/ fun finalize(): kotlin.Unit
public final override /*1*/ /*fake_override*/ /*isHiddenForResolutionEverywhereBesideSupercalls*/ fun getDeclaringClass(): java.lang.Class<First!>!
@@ -27,8 +25,6 @@ public final data enum class First : kotlin.Enum<First> {
public final data annotation class Fourth : kotlin.Annotation {
public constructor Fourth(/*0*/ x: kotlin.Int)
public final val x: kotlin.Int
public final operator /*synthesized*/ fun component1(): kotlin.Int
public final /*synthesized*/ fun copy(/*0*/ x: kotlin.Int = ...): Fourth
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
@@ -36,7 +32,6 @@ public final data annotation class Fourth : kotlin.Annotation {
public data object Second {
private constructor Second()
public final /*synthesized*/ fun copy(): Second
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
@@ -47,3 +42,4 @@ public data interface Third {
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
}
@@ -0,0 +1,44 @@
// FIR_IDENTICAL
// LANGUAGE: +DataObjects
data object Override {
<!DATA_OBJECT_CUSTOM_EQUALS_OR_HASH_CODE!>override<!> fun equals(other: Any?): Boolean {
return true
}
<!DATA_OBJECT_CUSTOM_EQUALS_OR_HASH_CODE!>override<!> fun hashCode(): Int {
return 1
}
}
open class Base {
open fun hashCode(x: Int) = x
}
data object NoOverride: Base() {
fun equals(other: Any?, tag: Int): Boolean {
return true
}
fun hashCode(param: String): Int {
return 1
}
override fun hashCode(x: Int) = x + 1
}
open class Super {
override fun equals(other: Any?): Boolean {
return super.equals(other)
}
override fun hashCode(): Int {
return 1
}
}
data object OverridenInSuper: Super() {
<!DATA_OBJECT_CUSTOM_EQUALS_OR_HASH_CODE!>override<!> fun equals(other: Any?): Boolean {
return super.equals(other)
}
}
@@ -0,0 +1,40 @@
package
public open class Base {
public constructor Base()
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
public open fun hashCode(/*0*/ x: kotlin.Int): kotlin.Int
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
}
public data object NoOverride : Base {
private constructor NoOverride()
public open override /*1*/ /*synthesized*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
public final fun equals(/*0*/ other: kotlin.Any?, /*1*/ tag: kotlin.Int): kotlin.Boolean
public open override /*1*/ /*synthesized*/ fun hashCode(): kotlin.Int
public open override /*1*/ fun hashCode(/*0*/ x: kotlin.Int): kotlin.Int
public final fun hashCode(/*0*/ param: kotlin.String): kotlin.Int
public open override /*1*/ /*synthesized*/ fun toString(): kotlin.String
}
public data object Override {
private constructor Override()
public open override /*1*/ 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 data object OverridenInSuper : Super {
private constructor OverridenInSuper()
public open override /*1*/ 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 open class Super {
public constructor Super()
public open override /*1*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
public open override /*1*/ fun hashCode(): kotlin.Int
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
}
@@ -0,0 +1,16 @@
// !LANGUAGE: +DataObjects
// TARGET_BACKEND: JVM_IR
import java.io.Serializable
data <!CONFLICTING_JVM_DECLARATIONS!>object A<!> : Serializable {
<!CONFLICTING_JVM_DECLARATIONS!>private fun readResolve(): Any<!> = this
}
data object B : Serializable {
private fun readResolve(): B = this
}
data object C {
private fun readResolve(): Any = this
}
@@ -0,0 +1,26 @@
package
public data object A : java.io.Serializable {
private constructor A()
public open override /*1*/ /*synthesized*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
public open override /*1*/ /*synthesized*/ fun hashCode(): kotlin.Int
private final fun readResolve(): kotlin.Any
public open override /*1*/ /*synthesized*/ fun toString(): kotlin.String
}
public data object B : java.io.Serializable {
private constructor B()
public open override /*1*/ /*synthesized*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
public open override /*1*/ /*synthesized*/ fun hashCode(): kotlin.Int
private final fun readResolve(): B
public open override /*1*/ /*synthesized*/ fun toString(): kotlin.String
}
public data object C {
private constructor C()
public open override /*1*/ /*synthesized*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
public open override /*1*/ /*synthesized*/ fun hashCode(): kotlin.Int
private final fun readResolve(): kotlin.Any
public open override /*1*/ /*synthesized*/ fun toString(): kotlin.String
}