diff --git a/compiler/fir/fir2ir/src/org/jetbrains/kotlin/fir/backend/generators/DataClassMembersGenerator.kt b/compiler/fir/fir2ir/src/org/jetbrains/kotlin/fir/backend/generators/DataClassMembersGenerator.kt index 8f7ee3c1f52..3089e78ec92 100644 --- a/compiler/fir/fir2ir/src/org/jetbrains/kotlin/fir/backend/generators/DataClassMembersGenerator.kt +++ b/compiler/fir/fir2ir/src/org/jetbrains/kotlin/fir/backend/generators/DataClassMembersGenerator.kt @@ -132,7 +132,7 @@ class DataClassMembersGenerator(val components: Fir2IrComponents) : Fir2IrCompon get() { // Pick the (necessarily unique) non-interface upper bound if it exists for (type in bounds) { - val klass = type.coneType.nothingToAny().toRegularClassSymbol(session)?.fir ?: continue + val klass = type.coneType.coerceToAny().toRegularClassSymbol(session)?.fir ?: continue val kind = klass.classKind if (kind != ClassKind.INTERFACE && kind != ClassKind.ANNOTATION_CLASS) return klass } @@ -140,7 +140,7 @@ class DataClassMembersGenerator(val components: Fir2IrComponents) : Fir2IrCompon // Otherwise, choose either the first IrClass supertype or recurse. // In the first case, all supertypes are interface types and the choice was arbitrary. // In the second case, there is only a single supertype. - val firstBoundType = bounds.first().coneType.fullyExpandedType(session).nothingToAny() + val firstBoundType = bounds.first().coneType.fullyExpandedType(session).coerceToAny() return when (val firstSuper = firstBoundType.toSymbol(session)?.fir) { is FirRegularClass -> firstSuper is FirTypeParameter -> firstSuper.erasedUpperBound @@ -161,7 +161,7 @@ class DataClassMembersGenerator(val components: Fir2IrComponents) : Fir2IrCompon val symbol = when { type.isArrayOrPrimitiveArray(checkUnsignedArrays = false) -> context.irBuiltIns.dataClassArrayMemberHashCodeSymbol else -> { - val classForType = when (val classifier = type.nothingToAny().toSymbol(session)?.fir) { + val classForType = when (val classifier = type.coerceToAny().toSymbol(session)?.fir) { is FirRegularClass -> classifier is FirTypeParameter -> classifier.erasedUpperBound else -> error("Unknown classifier kind $classifier") @@ -176,11 +176,12 @@ class DataClassMembersGenerator(val components: Fir2IrComponents) : Fir2IrCompon } /** - * kotlin.Nothing has no members, so any function on property of type Nothing should be actually taken from kotlin.Any + * Convert types which do not have members - kotlin.Nothing and `dynamic` - to kotlin.Any. */ - private fun ConeKotlinType.nothingToAny(): ConeKotlinType { + private fun ConeKotlinType.coerceToAny(): ConeKotlinType { return when { this.isNothingOrNullableNothing -> session.builtinTypes.anyType.type + this is ConeDynamicType -> session.builtinTypes.anyType.type else -> this } } diff --git a/compiler/testData/ir/irText/js/dynamic/dynamicInDataClass.fir.ir.txt b/compiler/testData/ir/irText/js/dynamic/dynamicInDataClass.fir.ir.txt new file mode 100644 index 00000000000..8d12bd042df --- /dev/null +++ b/compiler/testData/ir/irText/js/dynamic/dynamicInDataClass.fir.ir.txt @@ -0,0 +1,157 @@ +FILE fqName: fileName:/dynamicInDataClass.kt + CLASS CLASS name:Some modality:FINAL visibility:public [data] superTypes:[kotlin.Any] + $this: VALUE_PARAMETER INSTANCE_RECEIVER name: type:.Some + CONSTRUCTOR visibility:public <> (a:kotlin.String, b:dynamic) returnType:.Some [primary] + VALUE_PARAMETER name:a index:0 type:kotlin.String + VALUE_PARAMETER name:b index:1 type:dynamic + BLOCK_BODY + DELEGATING_CONSTRUCTOR_CALL 'public constructor () declared in kotlin.Any' + INSTANCE_INITIALIZER_CALL classDescriptor='CLASS CLASS name:Some modality:FINAL visibility:public [data] superTypes:[kotlin.Any]' + PROPERTY name:a visibility:public modality:FINAL [val] + FIELD PROPERTY_BACKING_FIELD name:a type:kotlin.String visibility:private [final] + EXPRESSION_BODY + GET_VAR 'a: kotlin.String declared in .Some.' type=kotlin.String origin=INITIALIZE_PROPERTY_FROM_PARAMETER + FUN DEFAULT_PROPERTY_ACCESSOR name: visibility:public modality:FINAL <> ($this:.Some) returnType:kotlin.String + correspondingProperty: PROPERTY name:a visibility:public modality:FINAL [val] + $this: VALUE_PARAMETER name: type:.Some + BLOCK_BODY + RETURN type=kotlin.Nothing from='public final fun (): kotlin.String declared in .Some' + GET_FIELD 'FIELD PROPERTY_BACKING_FIELD name:a type:kotlin.String visibility:private [final]' type=kotlin.String origin=null + receiver: GET_VAR ': .Some declared in .Some.' type=.Some origin=null + PROPERTY name:b visibility:public modality:FINAL [val] + FIELD PROPERTY_BACKING_FIELD name:b type:dynamic visibility:private [final] + EXPRESSION_BODY + GET_VAR 'b: dynamic declared in .Some.' type=dynamic origin=INITIALIZE_PROPERTY_FROM_PARAMETER + FUN DEFAULT_PROPERTY_ACCESSOR name: visibility:public modality:FINAL <> ($this:.Some) returnType:dynamic + correspondingProperty: PROPERTY name:b visibility:public modality:FINAL [val] + $this: VALUE_PARAMETER name: type:.Some + BLOCK_BODY + RETURN type=kotlin.Nothing from='public final fun (): dynamic declared in .Some' + GET_FIELD 'FIELD PROPERTY_BACKING_FIELD name:b type:dynamic visibility:private [final]' type=dynamic origin=null + receiver: GET_VAR ': .Some declared in .Some.' type=.Some origin=null + FUN GENERATED_DATA_CLASS_MEMBER name:component1 visibility:public modality:FINAL <> ($this:.Some) returnType:kotlin.String [operator] + $this: VALUE_PARAMETER name: type:.Some + BLOCK_BODY + RETURN type=kotlin.Nothing from='public final fun component1 (): kotlin.String declared in .Some' + GET_FIELD 'FIELD PROPERTY_BACKING_FIELD name:a type:kotlin.String visibility:private [final]' type=kotlin.String origin=null + receiver: GET_VAR ': .Some declared in .Some.component1' type=.Some origin=null + FUN GENERATED_DATA_CLASS_MEMBER name:component2 visibility:public modality:FINAL <> ($this:.Some) returnType:dynamic [operator] + $this: VALUE_PARAMETER name: type:.Some + BLOCK_BODY + RETURN type=kotlin.Nothing from='public final fun component2 (): dynamic declared in .Some' + GET_FIELD 'FIELD PROPERTY_BACKING_FIELD name:b type:dynamic visibility:private [final]' type=dynamic origin=null + receiver: GET_VAR ': .Some declared in .Some.component2' type=.Some origin=null + FUN GENERATED_DATA_CLASS_MEMBER name:copy visibility:public modality:FINAL <> ($this:.Some, a:kotlin.String, b:dynamic) returnType:.Some + $this: VALUE_PARAMETER name: type:.Some + VALUE_PARAMETER name:a index:0 type:kotlin.String + EXPRESSION_BODY + GET_FIELD 'FIELD PROPERTY_BACKING_FIELD name:a type:kotlin.String visibility:private [final]' type=kotlin.String origin=null + receiver: GET_VAR ': .Some declared in .Some.copy' type=.Some origin=null + VALUE_PARAMETER name:b index:1 type:dynamic + EXPRESSION_BODY + GET_FIELD 'FIELD PROPERTY_BACKING_FIELD name:b type:dynamic visibility:private [final]' type=dynamic origin=null + receiver: GET_VAR ': .Some declared in .Some.copy' type=.Some origin=null + BLOCK_BODY + RETURN type=kotlin.Nothing from='public final fun copy (a: kotlin.String, b: dynamic): .Some declared in .Some' + CONSTRUCTOR_CALL 'public constructor (a: kotlin.String, b: dynamic) declared in .Some' type=.Some origin=null + a: GET_VAR 'a: kotlin.String declared in .Some.copy' type=kotlin.String origin=null + b: GET_VAR 'b: dynamic declared in .Some.copy' type=dynamic origin=null + FUN GENERATED_DATA_CLASS_MEMBER name:toString visibility:public modality:OPEN <> ($this:.Some) returnType:kotlin.String + overridden: + public open fun toString (): kotlin.String declared in kotlin.Any + $this: VALUE_PARAMETER name: type:.Some + BLOCK_BODY + RETURN type=kotlin.Nothing from='public open fun toString (): kotlin.String declared in .Some' + STRING_CONCATENATION type=kotlin.String + CONST String type=kotlin.String value="Some(" + CONST String type=kotlin.String value="a=" + GET_FIELD 'FIELD PROPERTY_BACKING_FIELD name:a type:kotlin.String visibility:private [final]' type=kotlin.String origin=null + receiver: GET_VAR ': .Some declared in .Some.toString' type=.Some origin=null + CONST String type=kotlin.String value=", " + CONST String type=kotlin.String value="b=" + GET_FIELD 'FIELD PROPERTY_BACKING_FIELD name:b type:dynamic visibility:private [final]' type=dynamic origin=null + receiver: GET_VAR ': .Some declared in .Some.toString' type=.Some origin=null + CONST String type=kotlin.String value=")" + FUN GENERATED_DATA_CLASS_MEMBER name:hashCode visibility:public modality:OPEN <> ($this:.Some) returnType:kotlin.Int + overridden: + public open fun hashCode (): kotlin.Int declared in kotlin.Any + $this: VALUE_PARAMETER name: type:.Some + BLOCK_BODY + VAR name:result type:kotlin.Int [var] + CALL 'public open fun hashCode (): kotlin.Int declared in kotlin.String' type=kotlin.Int origin=null + $this: GET_FIELD 'FIELD PROPERTY_BACKING_FIELD name:a type:kotlin.String visibility:private [final]' type=kotlin.String origin=null + receiver: GET_VAR ': .Some declared in .Some.hashCode' type=.Some origin=null + SET_VAR 'var result: kotlin.Int declared in .Some.hashCode' type=kotlin.Unit origin=EQ + CALL 'public final fun plus (other: kotlin.Int): kotlin.Int declared in kotlin.Int' type=kotlin.Int origin=null + $this: CALL 'public final fun times (other: kotlin.Int): kotlin.Int declared in kotlin.Int' type=kotlin.Int origin=null + $this: GET_VAR 'var result: kotlin.Int declared in .Some.hashCode' type=kotlin.Int origin=null + other: CONST Int type=kotlin.Int value=31 + other: WHEN type=kotlin.Int origin=null + BRANCH + if: CALL 'public final fun EQEQ (arg0: kotlin.Any?, arg1: kotlin.Any?): kotlin.Boolean declared in kotlin.internal.ir' type=kotlin.Boolean origin=EQEQ + arg0: GET_FIELD 'FIELD PROPERTY_BACKING_FIELD name:b type:dynamic visibility:private [final]' type=dynamic origin=null + receiver: GET_VAR ': .Some declared in .Some.hashCode' type=.Some origin=null + arg1: CONST Null type=kotlin.Nothing? value=null + then: CONST Int type=kotlin.Int value=0 + BRANCH + if: CONST Boolean type=kotlin.Boolean value=true + then: CALL 'public open fun hashCode (): kotlin.Int declared in kotlin.Any' type=kotlin.Int origin=null + $this: GET_FIELD 'FIELD PROPERTY_BACKING_FIELD name:b type:dynamic visibility:private [final]' type=dynamic origin=null + receiver: GET_VAR ': .Some declared in .Some.hashCode' type=.Some origin=null + RETURN type=kotlin.Nothing from='public open fun hashCode (): kotlin.Int declared in .Some' + GET_VAR 'var result: kotlin.Int declared in .Some.hashCode' type=kotlin.Int origin=null + FUN GENERATED_DATA_CLASS_MEMBER name:equals visibility:public modality:OPEN <> ($this:.Some, other:kotlin.Any?) returnType:kotlin.Boolean [operator] + overridden: + public open fun equals (other: kotlin.Any?): kotlin.Boolean declared in kotlin.Any + $this: VALUE_PARAMETER name: type:.Some + VALUE_PARAMETER name:other index:0 type:kotlin.Any? + BLOCK_BODY + WHEN type=kotlin.Unit origin=null + BRANCH + if: CALL 'public final fun EQEQEQ (arg0: kotlin.Any?, arg1: kotlin.Any?): kotlin.Boolean declared in kotlin.internal.ir' type=kotlin.Boolean origin=EQEQEQ + arg0: GET_VAR ': .Some declared in .Some.equals' type=.Some origin=null + arg1: GET_VAR 'other: kotlin.Any? declared in .Some.equals' type=kotlin.Any? origin=null + then: RETURN type=kotlin.Nothing from='public open fun equals (other: kotlin.Any?): kotlin.Boolean declared in .Some' + CONST Boolean type=kotlin.Boolean value=true + WHEN type=kotlin.Unit origin=null + BRANCH + if: TYPE_OP type=kotlin.Boolean origin=NOT_INSTANCEOF typeOperand=.Some + GET_VAR 'other: kotlin.Any? declared in .Some.equals' type=kotlin.Any? origin=null + then: RETURN type=kotlin.Nothing from='public open fun equals (other: kotlin.Any?): kotlin.Boolean declared in .Some' + CONST Boolean type=kotlin.Boolean value=false + VAR IR_TEMPORARY_VARIABLE name:tmp_0 type:.Some [val] + TYPE_OP type=.Some origin=CAST typeOperand=.Some + GET_VAR 'other: kotlin.Any? declared in .Some.equals' type=kotlin.Any? origin=null + WHEN type=kotlin.Unit origin=null + BRANCH + if: CALL 'public final fun not (): kotlin.Boolean declared in kotlin.Boolean' type=kotlin.Boolean origin=EXCLEQ + $this: CALL 'public final fun EQEQ (arg0: kotlin.Any?, arg1: kotlin.Any?): kotlin.Boolean declared in kotlin.internal.ir' type=kotlin.Boolean origin=EXCLEQ + arg0: GET_FIELD 'FIELD PROPERTY_BACKING_FIELD name:a type:kotlin.String visibility:private [final]' type=kotlin.String origin=null + receiver: GET_VAR ': .Some declared in .Some.equals' type=.Some origin=null + arg1: GET_FIELD 'FIELD PROPERTY_BACKING_FIELD name:a type:kotlin.String visibility:private [final]' type=kotlin.String origin=null + receiver: GET_VAR 'val tmp_0: .Some declared in .Some.equals' type=.Some origin=null + then: RETURN type=kotlin.Nothing from='public open fun equals (other: kotlin.Any?): kotlin.Boolean declared in .Some' + CONST Boolean type=kotlin.Boolean value=false + WHEN type=kotlin.Unit origin=null + BRANCH + if: CALL 'public final fun not (): kotlin.Boolean declared in kotlin.Boolean' type=kotlin.Boolean origin=EXCLEQ + $this: CALL 'public final fun EQEQ (arg0: kotlin.Any?, arg1: kotlin.Any?): kotlin.Boolean declared in kotlin.internal.ir' type=kotlin.Boolean origin=EXCLEQ + arg0: GET_FIELD 'FIELD PROPERTY_BACKING_FIELD name:b type:dynamic visibility:private [final]' type=dynamic origin=null + receiver: GET_VAR ': .Some declared in .Some.equals' type=.Some origin=null + arg1: GET_FIELD 'FIELD PROPERTY_BACKING_FIELD name:b type:dynamic visibility:private [final]' type=dynamic origin=null + receiver: GET_VAR 'val tmp_0: .Some declared in .Some.equals' type=.Some origin=null + then: RETURN type=kotlin.Nothing from='public open fun equals (other: kotlin.Any?): kotlin.Boolean declared in .Some' + CONST Boolean type=kotlin.Boolean value=false + RETURN type=kotlin.Nothing from='public open fun equals (other: kotlin.Any?): kotlin.Boolean declared in .Some' + CONST Boolean type=kotlin.Boolean value=true + FUN name:box visibility:public modality:FINAL <> () returnType:kotlin.String + BLOCK_BODY + VAR name:event type:.Some [val] + CONSTRUCTOR_CALL 'public constructor (a: kotlin.String, b: dynamic) declared in .Some' type=.Some origin=null + a: CONST String type=kotlin.String value="O" + b: CONST String type=kotlin.String value="K" + TYPE_OP type=kotlin.Unit origin=IMPLICIT_COERCION_TO_UNIT typeOperand=kotlin.Unit + CALL 'public open fun hashCode (): kotlin.Int declared in .Some' type=kotlin.Int origin=null + $this: GET_VAR 'val event: .Some declared in .box' type=.Some origin=null + RETURN type=kotlin.Nothing from='public final fun box (): kotlin.String declared in ' + CONST String type=kotlin.String value="OK" diff --git a/compiler/testData/ir/irText/js/dynamic/dynamicInDataClass.fir.kt.txt b/compiler/testData/ir/irText/js/dynamic/dynamicInDataClass.fir.kt.txt new file mode 100644 index 00000000000..565b3fa909b --- /dev/null +++ b/compiler/testData/ir/irText/js/dynamic/dynamicInDataClass.fir.kt.txt @@ -0,0 +1,64 @@ +data class Some { + constructor(a: String, b: dynamic) /* primary */ { + super/*Any*/() + /* () */ + + } + + val a: String + field = a + get + + val b: dynamic + field = b + get + + operator fun component1(): String { + return .#a + } + + operator fun component2(): dynamic { + return .#b + } + + fun copy(a: String = .#a, b: dynamic = .#b): Some { + return Some(a = a, b = b) + } + + override fun toString(): String { + return "Some(" + "a=" + .#a + ", " + "b=" + .#b + ")" + } + + override fun hashCode(): Int { + var result: Int = .#a.hashCode() + result = result.times(other = 31).plus(other = when { + EQEQ(arg0 = .#b, arg1 = null) -> 0 + else -> .#b.hashCode() + }) + return result + } + + override operator fun equals(other: Any?): Boolean { + when { + EQEQEQ(arg0 = , arg1 = other) -> return true + } + when { + other !is Some -> return false + } + val tmp_0: Some = other as Some + when { + EQEQ(arg0 = .#a, arg1 = tmp_0.#a).not() -> return false + } + when { + EQEQ(arg0 = .#b, arg1 = tmp_0.#b).not() -> return false + } + return true + } + +} + +fun box(): String { + val event: Some = Some(a = "O", b = "K") + event.hashCode() /*~> Unit */ + return "OK" +} diff --git a/compiler/testData/ir/irText/js/dynamic/dynamicInDataClass.ir.txt b/compiler/testData/ir/irText/js/dynamic/dynamicInDataClass.ir.txt new file mode 100644 index 00000000000..f7b9f44d04b --- /dev/null +++ b/compiler/testData/ir/irText/js/dynamic/dynamicInDataClass.ir.txt @@ -0,0 +1,158 @@ +FILE fqName: fileName:/dynamicInDataClass.kt + CLASS CLASS name:Some modality:FINAL visibility:public [data] superTypes:[kotlin.Any] + $this: VALUE_PARAMETER INSTANCE_RECEIVER name: type:.Some + CONSTRUCTOR visibility:public <> (a:kotlin.String, b:dynamic) returnType:.Some [primary] + VALUE_PARAMETER name:a index:0 type:kotlin.String + VALUE_PARAMETER name:b index:1 type:dynamic + BLOCK_BODY + DELEGATING_CONSTRUCTOR_CALL 'public constructor () declared in kotlin.Any' + INSTANCE_INITIALIZER_CALL classDescriptor='CLASS CLASS name:Some modality:FINAL visibility:public [data] superTypes:[kotlin.Any]' + PROPERTY name:a visibility:public modality:FINAL [val] + FIELD PROPERTY_BACKING_FIELD name:a type:kotlin.String visibility:private [final] + EXPRESSION_BODY + GET_VAR 'a: kotlin.String declared in .Some.' type=kotlin.String origin=INITIALIZE_PROPERTY_FROM_PARAMETER + FUN DEFAULT_PROPERTY_ACCESSOR name: visibility:public modality:FINAL <> ($this:.Some) returnType:kotlin.String + correspondingProperty: PROPERTY name:a visibility:public modality:FINAL [val] + $this: VALUE_PARAMETER name: type:.Some + BLOCK_BODY + RETURN type=kotlin.Nothing from='public final fun (): kotlin.String declared in .Some' + GET_FIELD 'FIELD PROPERTY_BACKING_FIELD name:a type:kotlin.String visibility:private [final]' type=kotlin.String origin=null + receiver: GET_VAR ': .Some declared in .Some.' type=.Some origin=null + PROPERTY name:b visibility:public modality:FINAL [val] + FIELD PROPERTY_BACKING_FIELD name:b type:dynamic visibility:private [final] + EXPRESSION_BODY + GET_VAR 'b: dynamic declared in .Some.' type=dynamic origin=INITIALIZE_PROPERTY_FROM_PARAMETER + FUN DEFAULT_PROPERTY_ACCESSOR name: visibility:public modality:FINAL <> ($this:.Some) returnType:dynamic + correspondingProperty: PROPERTY name:b visibility:public modality:FINAL [val] + $this: VALUE_PARAMETER name: type:.Some + BLOCK_BODY + RETURN type=kotlin.Nothing from='public final fun (): dynamic declared in .Some' + GET_FIELD 'FIELD PROPERTY_BACKING_FIELD name:b type:dynamic visibility:private [final]' type=dynamic origin=null + receiver: GET_VAR ': .Some declared in .Some.' type=.Some origin=null + FUN GENERATED_DATA_CLASS_MEMBER name:component1 visibility:public modality:FINAL <> ($this:.Some) returnType:kotlin.String [operator] + $this: VALUE_PARAMETER name: type:.Some + BLOCK_BODY + RETURN type=kotlin.Nothing from='public final fun component1 (): kotlin.String declared in .Some' + GET_FIELD 'FIELD PROPERTY_BACKING_FIELD name:a type:kotlin.String visibility:private [final]' type=kotlin.String origin=null + receiver: GET_VAR ': .Some declared in .Some.component1' type=.Some origin=null + FUN GENERATED_DATA_CLASS_MEMBER name:component2 visibility:public modality:FINAL <> ($this:.Some) returnType:dynamic [operator] + $this: VALUE_PARAMETER name: type:.Some + BLOCK_BODY + RETURN type=kotlin.Nothing from='public final fun component2 (): dynamic declared in .Some' + GET_FIELD 'FIELD PROPERTY_BACKING_FIELD name:b type:dynamic visibility:private [final]' type=dynamic origin=null + receiver: GET_VAR ': .Some declared in .Some.component2' type=.Some origin=null + FUN GENERATED_DATA_CLASS_MEMBER name:copy visibility:public modality:FINAL <> ($this:.Some, a:kotlin.String, b:dynamic) returnType:.Some + $this: VALUE_PARAMETER name: type:.Some + VALUE_PARAMETER name:a index:0 type:kotlin.String + EXPRESSION_BODY + GET_FIELD 'FIELD PROPERTY_BACKING_FIELD name:a type:kotlin.String visibility:private [final]' type=kotlin.String origin=null + receiver: GET_VAR ': .Some declared in .Some.copy' type=.Some origin=null + VALUE_PARAMETER name:b index:1 type:dynamic + EXPRESSION_BODY + GET_FIELD 'FIELD PROPERTY_BACKING_FIELD name:b type:dynamic visibility:private [final]' type=dynamic origin=null + receiver: GET_VAR ': .Some declared in .Some.copy' type=.Some origin=null + BLOCK_BODY + RETURN type=kotlin.Nothing from='public final fun copy (a: kotlin.String, b: dynamic): .Some declared in .Some' + CONSTRUCTOR_CALL 'public constructor (a: kotlin.String, b: dynamic) declared in .Some' type=.Some origin=null + a: GET_VAR 'a: kotlin.String declared in .Some.copy' type=kotlin.String origin=null + b: GET_VAR 'b: dynamic declared in .Some.copy' type=dynamic origin=null + FUN GENERATED_DATA_CLASS_MEMBER name:toString visibility:public modality:OPEN <> ($this:.Some) returnType:kotlin.String + overridden: + public open fun toString (): kotlin.String declared in kotlin.Any + $this: VALUE_PARAMETER name: type:.Some + BLOCK_BODY + RETURN type=kotlin.Nothing from='public open fun toString (): kotlin.String declared in .Some' + STRING_CONCATENATION type=kotlin.String + CONST String type=kotlin.String value="Some(" + CONST String type=kotlin.String value="a=" + GET_FIELD 'FIELD PROPERTY_BACKING_FIELD name:a type:kotlin.String visibility:private [final]' type=kotlin.String origin=null + receiver: GET_VAR ': .Some declared in .Some.toString' type=.Some origin=null + CONST String type=kotlin.String value=", " + CONST String type=kotlin.String value="b=" + GET_FIELD 'FIELD PROPERTY_BACKING_FIELD name:b type:dynamic visibility:private [final]' type=dynamic origin=null + receiver: GET_VAR ': .Some declared in .Some.toString' type=.Some origin=null + CONST String type=kotlin.String value=")" + FUN GENERATED_DATA_CLASS_MEMBER name:hashCode visibility:public modality:OPEN <> ($this:.Some) returnType:kotlin.Int + overridden: + public open fun hashCode (): kotlin.Int declared in kotlin.Any + $this: VALUE_PARAMETER name: type:.Some + BLOCK_BODY + VAR name:result type:kotlin.Int [var] + CALL 'public open fun hashCode (): kotlin.Int declared in kotlin.String' type=kotlin.Int origin=null + $this: GET_FIELD 'FIELD PROPERTY_BACKING_FIELD name:a type:kotlin.String visibility:private [final]' type=kotlin.String origin=null + receiver: GET_VAR ': .Some declared in .Some.hashCode' type=.Some origin=null + SET_VAR 'var result: kotlin.Int declared in .Some.hashCode' type=kotlin.Unit origin=EQ + CALL 'public final fun plus (other: kotlin.Int): kotlin.Int declared in kotlin.Int' type=kotlin.Int origin=null + $this: CALL 'public final fun times (other: kotlin.Int): kotlin.Int declared in kotlin.Int' type=kotlin.Int origin=null + $this: GET_VAR 'var result: kotlin.Int declared in .Some.hashCode' type=kotlin.Int origin=null + other: CONST Int type=kotlin.Int value=31 + other: WHEN type=kotlin.Int origin=null + BRANCH + if: CALL 'public final fun EQEQ (arg0: kotlin.Any?, arg1: kotlin.Any?): kotlin.Boolean declared in kotlin.internal.ir' type=kotlin.Boolean origin=EQEQ + arg0: GET_FIELD 'FIELD PROPERTY_BACKING_FIELD name:b type:dynamic visibility:private [final]' type=dynamic origin=null + receiver: GET_VAR ': .Some declared in .Some.hashCode' type=.Some origin=null + arg1: CONST Null type=kotlin.Nothing? value=null + then: CONST Int type=kotlin.Int value=0 + BRANCH + if: CONST Boolean type=kotlin.Boolean value=true + then: CALL 'public open fun hashCode (): kotlin.Int declared in kotlin.Any' type=kotlin.Int origin=null + $this: TYPE_OP type=kotlin.Any origin=IMPLICIT_DYNAMIC_CAST typeOperand=kotlin.Any + GET_FIELD 'FIELD PROPERTY_BACKING_FIELD name:b type:dynamic visibility:private [final]' type=dynamic origin=null + receiver: GET_VAR ': .Some declared in .Some.hashCode' type=.Some origin=null + RETURN type=kotlin.Nothing from='public open fun hashCode (): kotlin.Int declared in .Some' + GET_VAR 'var result: kotlin.Int declared in .Some.hashCode' type=kotlin.Int origin=null + FUN GENERATED_DATA_CLASS_MEMBER name:equals visibility:public modality:OPEN <> ($this:.Some, other:kotlin.Any?) returnType:kotlin.Boolean [operator] + overridden: + public open fun equals (other: kotlin.Any?): kotlin.Boolean declared in kotlin.Any + $this: VALUE_PARAMETER name: type:.Some + VALUE_PARAMETER name:other index:0 type:kotlin.Any? + BLOCK_BODY + WHEN type=kotlin.Unit origin=null + BRANCH + if: CALL 'public final fun EQEQEQ (arg0: kotlin.Any?, arg1: kotlin.Any?): kotlin.Boolean declared in kotlin.internal.ir' type=kotlin.Boolean origin=EQEQEQ + arg0: GET_VAR ': .Some declared in .Some.equals' type=.Some origin=null + arg1: GET_VAR 'other: kotlin.Any? declared in .Some.equals' type=kotlin.Any? origin=null + then: RETURN type=kotlin.Nothing from='public open fun equals (other: kotlin.Any?): kotlin.Boolean declared in .Some' + CONST Boolean type=kotlin.Boolean value=true + WHEN type=kotlin.Unit origin=null + BRANCH + if: TYPE_OP type=kotlin.Boolean origin=NOT_INSTANCEOF typeOperand=.Some + GET_VAR 'other: kotlin.Any? declared in .Some.equals' type=kotlin.Any? origin=null + then: RETURN type=kotlin.Nothing from='public open fun equals (other: kotlin.Any?): kotlin.Boolean declared in .Some' + CONST Boolean type=kotlin.Boolean value=false + VAR IR_TEMPORARY_VARIABLE name:tmp_0 type:.Some [val] + TYPE_OP type=.Some origin=CAST typeOperand=.Some + GET_VAR 'other: kotlin.Any? declared in .Some.equals' type=kotlin.Any? origin=null + WHEN type=kotlin.Unit origin=null + BRANCH + if: CALL 'public final fun not (): kotlin.Boolean declared in kotlin.Boolean' type=kotlin.Boolean origin=EXCLEQ + $this: CALL 'public final fun EQEQ (arg0: kotlin.Any?, arg1: kotlin.Any?): kotlin.Boolean declared in kotlin.internal.ir' type=kotlin.Boolean origin=EXCLEQ + arg0: GET_FIELD 'FIELD PROPERTY_BACKING_FIELD name:a type:kotlin.String visibility:private [final]' type=kotlin.String origin=null + receiver: GET_VAR ': .Some declared in .Some.equals' type=.Some origin=null + arg1: GET_FIELD 'FIELD PROPERTY_BACKING_FIELD name:a type:kotlin.String visibility:private [final]' type=kotlin.String origin=null + receiver: GET_VAR 'val tmp_0: .Some declared in .Some.equals' type=.Some origin=null + then: RETURN type=kotlin.Nothing from='public open fun equals (other: kotlin.Any?): kotlin.Boolean declared in .Some' + CONST Boolean type=kotlin.Boolean value=false + WHEN type=kotlin.Unit origin=null + BRANCH + if: CALL 'public final fun not (): kotlin.Boolean declared in kotlin.Boolean' type=kotlin.Boolean origin=EXCLEQ + $this: CALL 'public final fun EQEQ (arg0: kotlin.Any?, arg1: kotlin.Any?): kotlin.Boolean declared in kotlin.internal.ir' type=kotlin.Boolean origin=EXCLEQ + arg0: GET_FIELD 'FIELD PROPERTY_BACKING_FIELD name:b type:dynamic visibility:private [final]' type=dynamic origin=null + receiver: GET_VAR ': .Some declared in .Some.equals' type=.Some origin=null + arg1: GET_FIELD 'FIELD PROPERTY_BACKING_FIELD name:b type:dynamic visibility:private [final]' type=dynamic origin=null + receiver: GET_VAR 'val tmp_0: .Some declared in .Some.equals' type=.Some origin=null + then: RETURN type=kotlin.Nothing from='public open fun equals (other: kotlin.Any?): kotlin.Boolean declared in .Some' + CONST Boolean type=kotlin.Boolean value=false + RETURN type=kotlin.Nothing from='public open fun equals (other: kotlin.Any?): kotlin.Boolean declared in .Some' + CONST Boolean type=kotlin.Boolean value=true + FUN name:box visibility:public modality:FINAL <> () returnType:kotlin.String + BLOCK_BODY + VAR name:event type:.Some [val] + CONSTRUCTOR_CALL 'public constructor (a: kotlin.String, b: dynamic) declared in .Some' type=.Some origin=null + a: CONST String type=kotlin.String value="O" + b: CONST String type=kotlin.String value="K" + TYPE_OP type=kotlin.Unit origin=IMPLICIT_COERCION_TO_UNIT typeOperand=kotlin.Unit + CALL 'public open fun hashCode (): kotlin.Int declared in .Some' type=kotlin.Int origin=null + $this: GET_VAR 'val event: .Some declared in .box' type=.Some origin=null + RETURN type=kotlin.Nothing from='public final fun box (): kotlin.String declared in ' + CONST String type=kotlin.String value="OK" diff --git a/compiler/testData/ir/irText/js/dynamic/dynamicInDataClass.kt b/compiler/testData/ir/irText/js/dynamic/dynamicInDataClass.kt new file mode 100644 index 00000000000..b8c7a10a141 --- /dev/null +++ b/compiler/testData/ir/irText/js/dynamic/dynamicInDataClass.kt @@ -0,0 +1,9 @@ +// TARGET_BACKEND: JS_IR + +data class Some(val a: String, val b: dynamic) + +fun box(): String { + val event = Some("O", "K") + event.hashCode() + return "OK" +} \ No newline at end of file diff --git a/compiler/testData/ir/irText/js/dynamic/dynamicInDataClass.kt.txt b/compiler/testData/ir/irText/js/dynamic/dynamicInDataClass.kt.txt new file mode 100644 index 00000000000..fa0152364a0 --- /dev/null +++ b/compiler/testData/ir/irText/js/dynamic/dynamicInDataClass.kt.txt @@ -0,0 +1,64 @@ +data class Some { + constructor(a: String, b: dynamic) /* primary */ { + super/*Any*/() + /* () */ + + } + + val a: String + field = a + get + + val b: dynamic + field = b + get + + operator fun component1(): String { + return .#a + } + + operator fun component2(): dynamic { + return .#b + } + + fun copy(a: String = .#a, b: dynamic = .#b): Some { + return Some(a = a, b = b) + } + + override fun toString(): String { + return "Some(" + "a=" + .#a + ", " + "b=" + .#b + ")" + } + + override fun hashCode(): Int { + var result: Int = .#a.hashCode() + result = result.times(other = 31).plus(other = when { + EQEQ(arg0 = .#b, arg1 = null) -> 0 + else -> .#b /*~> Any */.hashCode() + }) + return result + } + + override operator fun equals(other: Any?): Boolean { + when { + EQEQEQ(arg0 = , arg1 = other) -> return true + } + when { + other !is Some -> return false + } + val tmp_0: Some = other as Some + when { + EQEQ(arg0 = .#a, arg1 = tmp_0.#a).not() -> return false + } + when { + EQEQ(arg0 = .#b, arg1 = tmp_0.#b).not() -> return false + } + return true + } + +} + +fun box(): String { + val event: Some = Some(a = "O", b = "K") + event.hashCode() /*~> Unit */ + return "OK" +} diff --git a/compiler/testData/ir/irText/js/dynamic/dynamicInDataClass.sig.kt.txt b/compiler/testData/ir/irText/js/dynamic/dynamicInDataClass.sig.kt.txt new file mode 100644 index 00000000000..6777f1cecb8 --- /dev/null +++ b/compiler/testData/ir/irText/js/dynamic/dynamicInDataClass.sig.kt.txt @@ -0,0 +1,74 @@ +// CHECK: +// Mangled name: Some +// Public signature: /Some|null[0] +data class Some { + // CHECK: + // Mangled name: Some{}a + // Public signature: /Some.a|-1200697420457237799[0] + // Public signature debug description: {}a + val a: String + // CHECK JS_IR NATIVE: + // Mangled name: Some#(){} + // Public signature: /Some.a.|6785176174175479410[0] + // Public signature debug description: (){} + get + + // CHECK: + // Mangled name: Some{}b + // Public signature: /Some.b|772347207915745207[0] + // Public signature debug description: {}b + val b: dynamic + // CHECK JS_IR NATIVE: + // Mangled name: Some#(){} + // Public signature: /Some.b.|812004636995167743[0] + // Public signature debug description: (){} + get + + // CHECK: + // Mangled name: Some#(kotlin.String;){} + // Public signature: /Some.|-5225459408480290556[0] + // Public signature debug description: (kotlin.String;){} + constructor(a: String, b: dynamic) /* primary */ + // CHECK JS_IR NATIVE: + // Mangled name: Some#component1(){} + // Public signature: /Some.component1|162597135895221648[0] + // Public signature debug description: component1(){} + operator fun component1(): String + + // CHECK JS_IR NATIVE: + // Mangled name: Some#component2(){} + // Public signature: /Some.component2|3796717572321500973[0] + // Public signature debug description: component2(){} + operator fun component2(): dynamic + + // CHECK JS_IR NATIVE: + // Mangled name: Some#copy(kotlin.String;){} + // Public signature: /Some.copy|-666200579701757332[0] + // Public signature debug description: copy(kotlin.String;){} + fun copy(a: String, b: dynamic): Some + + // CHECK JS_IR NATIVE: + // Mangled name: Some#equals(kotlin.Any?){} + // Public signature: /Some.equals|4638265728071529943[0] + // Public signature debug description: equals(kotlin.Any?){} + override operator fun equals(other: Any?): Boolean + + // CHECK JS_IR NATIVE: + // Mangled name: Some#hashCode(){} + // Public signature: /Some.hashCode|3409210261493131192[0] + // Public signature debug description: hashCode(){} + override fun hashCode(): Int + + // CHECK JS_IR NATIVE: + // Mangled name: Some#toString(){} + // Public signature: /Some.toString|-1522858123163872138[0] + // Public signature debug description: toString(){} + override fun toString(): String + +} + +// CHECK JS_IR NATIVE: +// Mangled name: #box(){} +// Public signature: /box|2173511048851971368[0] +// Public signature debug description: box(){} +fun box(): String diff --git a/compiler/tests-gen/org/jetbrains/kotlin/klib/KlibIrTextTestCaseGenerated.java b/compiler/tests-gen/org/jetbrains/kotlin/klib/KlibIrTextTestCaseGenerated.java index 6ff8e2deb6c..a9a2d10b84e 100644 --- a/compiler/tests-gen/org/jetbrains/kotlin/klib/KlibIrTextTestCaseGenerated.java +++ b/compiler/tests-gen/org/jetbrains/kotlin/klib/KlibIrTextTestCaseGenerated.java @@ -2283,6 +2283,11 @@ public class KlibIrTextTestCaseGenerated extends AbstractKlibIrTextTestCase { runTest("compiler/testData/ir/irText/js/dynamic/dynamicExclExclOperator.kt"); } + @TestMetadata("dynamicInDataClass.kt") + public void testDynamicInDataClass() throws Exception { + runTest("compiler/testData/ir/irText/js/dynamic/dynamicInDataClass.kt"); + } + @TestMetadata("dynamicInfixCall.kt") public void testDynamicInfixCall() throws Exception { runTest("compiler/testData/ir/irText/js/dynamic/dynamicInfixCall.kt"); diff --git a/compiler/tests-gen/org/jetbrains/kotlin/klib/KlibJsIrTextTestCaseGenerated.java b/compiler/tests-gen/org/jetbrains/kotlin/klib/KlibJsIrTextTestCaseGenerated.java index 161d5b744af..78e10f38b23 100644 --- a/compiler/tests-gen/org/jetbrains/kotlin/klib/KlibJsIrTextTestCaseGenerated.java +++ b/compiler/tests-gen/org/jetbrains/kotlin/klib/KlibJsIrTextTestCaseGenerated.java @@ -102,6 +102,11 @@ public class KlibJsIrTextTestCaseGenerated extends AbstractKlibJsIrTextTestCase runTest("compiler/testData/ir/irText/js/dynamic/dynamicExclExclOperator.kt"); } + @TestMetadata("dynamicInDataClass.kt") + public void testDynamicInDataClass() throws Exception { + runTest("compiler/testData/ir/irText/js/dynamic/dynamicInDataClass.kt"); + } + @TestMetadata("dynamicInfixCall.kt") public void testDynamicInfixCall() throws Exception { runTest("compiler/testData/ir/irText/js/dynamic/dynamicInfixCall.kt"); diff --git a/js/js.tests/tests-gen/org/jetbrains/kotlin/js/test/fir/FirLightTreeJsIrTextTestGenerated.java b/js/js.tests/tests-gen/org/jetbrains/kotlin/js/test/fir/FirLightTreeJsIrTextTestGenerated.java index ce9a98bda70..17d75268422 100644 --- a/js/js.tests/tests-gen/org/jetbrains/kotlin/js/test/fir/FirLightTreeJsIrTextTestGenerated.java +++ b/js/js.tests/tests-gen/org/jetbrains/kotlin/js/test/fir/FirLightTreeJsIrTextTestGenerated.java @@ -2617,6 +2617,12 @@ public class FirLightTreeJsIrTextTestGenerated extends AbstractFirLightTreeJsIrT runTest("compiler/testData/ir/irText/js/dynamic/dynamicExclExclOperator.kt"); } + @Test + @TestMetadata("dynamicInDataClass.kt") + public void testDynamicInDataClass() throws Exception { + runTest("compiler/testData/ir/irText/js/dynamic/dynamicInDataClass.kt"); + } + @Test @TestMetadata("dynamicInfixCall.kt") public void testDynamicInfixCall() throws Exception { diff --git a/js/js.tests/tests-gen/org/jetbrains/kotlin/js/test/fir/FirPsiJsIrTextTestGenerated.java b/js/js.tests/tests-gen/org/jetbrains/kotlin/js/test/fir/FirPsiJsIrTextTestGenerated.java index 7598cda3032..e8a6ee6b4b7 100644 --- a/js/js.tests/tests-gen/org/jetbrains/kotlin/js/test/fir/FirPsiJsIrTextTestGenerated.java +++ b/js/js.tests/tests-gen/org/jetbrains/kotlin/js/test/fir/FirPsiJsIrTextTestGenerated.java @@ -2617,6 +2617,12 @@ public class FirPsiJsIrTextTestGenerated extends AbstractFirPsiJsIrTextTest { runTest("compiler/testData/ir/irText/js/dynamic/dynamicExclExclOperator.kt"); } + @Test + @TestMetadata("dynamicInDataClass.kt") + public void testDynamicInDataClass() throws Exception { + runTest("compiler/testData/ir/irText/js/dynamic/dynamicInDataClass.kt"); + } + @Test @TestMetadata("dynamicInfixCall.kt") public void testDynamicInfixCall() throws Exception { diff --git a/js/js.tests/tests-gen/org/jetbrains/kotlin/js/test/ir/ClassicJsIrTextTestGenerated.java b/js/js.tests/tests-gen/org/jetbrains/kotlin/js/test/ir/ClassicJsIrTextTestGenerated.java index bddf89680fa..59001acaab7 100644 --- a/js/js.tests/tests-gen/org/jetbrains/kotlin/js/test/ir/ClassicJsIrTextTestGenerated.java +++ b/js/js.tests/tests-gen/org/jetbrains/kotlin/js/test/ir/ClassicJsIrTextTestGenerated.java @@ -2617,6 +2617,12 @@ public class ClassicJsIrTextTestGenerated extends AbstractClassicJsIrTextTest { runTest("compiler/testData/ir/irText/js/dynamic/dynamicExclExclOperator.kt"); } + @Test + @TestMetadata("dynamicInDataClass.kt") + public void testDynamicInDataClass() throws Exception { + runTest("compiler/testData/ir/irText/js/dynamic/dynamicInDataClass.kt"); + } + @Test @TestMetadata("dynamicInfixCall.kt") public void testDynamicInfixCall() throws Exception {