From 966e2442c6c4199aec43611f7d60253b050a8d5a Mon Sep 17 00:00:00 2001 From: Mikhail Glukhikh Date: Tue, 14 Jun 2022 18:41:15 +0200 Subject: [PATCH] Add tests for KT-52745 --- .../FirBlackBoxCodegenTestGenerated.java | 6 + .../runners/ir/Fir2IrTextTestGenerated.java | 6 + .../ir/LightTreeFir2IrTextTestGenerated.java | 6 + .../codegen/box/delegation/sealedClass.kt | 11 ++ .../dataClasses/delegationInSealed.fir.ir.txt | 167 +++++++++++++++++ .../dataClasses/delegationInSealed.fir.kt.txt | 64 +++++++ .../dataClasses/delegationInSealed.ir.txt | 174 ++++++++++++++++++ .../classes/dataClasses/delegationInSealed.kt | 6 + .../dataClasses/delegationInSealed.kt.txt | 64 +++++++ .../IrBlackBoxCodegenTestGenerated.java | 6 + .../test/runners/ir/IrTextTestGenerated.java | 6 + .../klib/KlibTextTestCaseGenerated.java | 5 + 12 files changed, 521 insertions(+) create mode 100644 compiler/testData/codegen/box/delegation/sealedClass.kt create mode 100644 compiler/testData/ir/irText/classes/dataClasses/delegationInSealed.fir.ir.txt create mode 100644 compiler/testData/ir/irText/classes/dataClasses/delegationInSealed.fir.kt.txt create mode 100644 compiler/testData/ir/irText/classes/dataClasses/delegationInSealed.ir.txt create mode 100644 compiler/testData/ir/irText/classes/dataClasses/delegationInSealed.kt create mode 100644 compiler/testData/ir/irText/classes/dataClasses/delegationInSealed.kt.txt diff --git a/compiler/fir/fir2ir/tests-gen/org/jetbrains/kotlin/test/runners/codegen/FirBlackBoxCodegenTestGenerated.java b/compiler/fir/fir2ir/tests-gen/org/jetbrains/kotlin/test/runners/codegen/FirBlackBoxCodegenTestGenerated.java index 1fd3765ad72..6c61bc2a5ca 100644 --- a/compiler/fir/fir2ir/tests-gen/org/jetbrains/kotlin/test/runners/codegen/FirBlackBoxCodegenTestGenerated.java +++ b/compiler/fir/fir2ir/tests-gen/org/jetbrains/kotlin/test/runners/codegen/FirBlackBoxCodegenTestGenerated.java @@ -15229,6 +15229,12 @@ public class FirBlackBoxCodegenTestGenerated extends AbstractFirBlackBoxCodegenT runTest("compiler/testData/codegen/box/delegation/mixed.kt"); } + @Test + @TestMetadata("sealedClass.kt") + public void testSealedClass() throws Exception { + runTest("compiler/testData/codegen/box/delegation/sealedClass.kt"); + } + @Test @TestMetadata("simple.kt") public void testSimple() throws Exception { diff --git a/compiler/fir/fir2ir/tests-gen/org/jetbrains/kotlin/test/runners/ir/Fir2IrTextTestGenerated.java b/compiler/fir/fir2ir/tests-gen/org/jetbrains/kotlin/test/runners/ir/Fir2IrTextTestGenerated.java index ceb812ca31f..f412d261583 100644 --- a/compiler/fir/fir2ir/tests-gen/org/jetbrains/kotlin/test/runners/ir/Fir2IrTextTestGenerated.java +++ b/compiler/fir/fir2ir/tests-gen/org/jetbrains/kotlin/test/runners/ir/Fir2IrTextTestGenerated.java @@ -337,6 +337,12 @@ public class Fir2IrTextTestGenerated extends AbstractFir2IrTextTest { runTest("compiler/testData/ir/irText/classes/dataClasses/dataClassesGeneric.kt"); } + @Test + @TestMetadata("delegationInSealed.kt") + public void testDelegationInSealed() throws Exception { + runTest("compiler/testData/ir/irText/classes/dataClasses/delegationInSealed.kt"); + } + @Test @TestMetadata("kt31649.kt") public void testKt31649() throws Exception { diff --git a/compiler/fir/fir2ir/tests-gen/org/jetbrains/kotlin/test/runners/ir/LightTreeFir2IrTextTestGenerated.java b/compiler/fir/fir2ir/tests-gen/org/jetbrains/kotlin/test/runners/ir/LightTreeFir2IrTextTestGenerated.java index d89bc042ee6..a2bebf40c76 100644 --- a/compiler/fir/fir2ir/tests-gen/org/jetbrains/kotlin/test/runners/ir/LightTreeFir2IrTextTestGenerated.java +++ b/compiler/fir/fir2ir/tests-gen/org/jetbrains/kotlin/test/runners/ir/LightTreeFir2IrTextTestGenerated.java @@ -337,6 +337,12 @@ public class LightTreeFir2IrTextTestGenerated extends AbstractLightTreeFir2IrTex runTest("compiler/testData/ir/irText/classes/dataClasses/dataClassesGeneric.kt"); } + @Test + @TestMetadata("delegationInSealed.kt") + public void testDelegationInSealed() throws Exception { + runTest("compiler/testData/ir/irText/classes/dataClasses/delegationInSealed.kt"); + } + @Test @TestMetadata("kt31649.kt") public void testKt31649() throws Exception { diff --git a/compiler/testData/codegen/box/delegation/sealedClass.kt b/compiler/testData/codegen/box/delegation/sealedClass.kt new file mode 100644 index 00000000000..52e831b38a4 --- /dev/null +++ b/compiler/testData/codegen/box/delegation/sealedClass.kt @@ -0,0 +1,11 @@ +// TARGET_BACKEND: JVM_IR +// IGNORE_BACKEND_FIR: JVM_IR +// WITH_STDLIB + +sealed class A : CharSequence { + data class B(val c: CharSequence) : A(), CharSequence by c +} + +fun box(): String { + return A.B("OK").c.toString() +} diff --git a/compiler/testData/ir/irText/classes/dataClasses/delegationInSealed.fir.ir.txt b/compiler/testData/ir/irText/classes/dataClasses/delegationInSealed.fir.ir.txt new file mode 100644 index 00000000000..98999113419 --- /dev/null +++ b/compiler/testData/ir/irText/classes/dataClasses/delegationInSealed.fir.ir.txt @@ -0,0 +1,167 @@ +FILE fqName: fileName:/delegationInSealed.kt + CLASS CLASS name:A modality:SEALED visibility:public superTypes:[kotlin.CharSequence] + sealedSubclasses: + CLASS CLASS name:B modality:FINAL visibility:public [data] superTypes:[.A; kotlin.CharSequence] + $this: VALUE_PARAMETER INSTANCE_RECEIVER name: type:.A + CONSTRUCTOR visibility:protected <> () returnType:.A [primary] + BLOCK_BODY + DELEGATING_CONSTRUCTOR_CALL 'public constructor () [primary] declared in kotlin.Any' + INSTANCE_INITIALIZER_CALL classDescriptor='CLASS CLASS name:A modality:SEALED visibility:public superTypes:[kotlin.CharSequence]' + CLASS CLASS name:B modality:FINAL visibility:public [data] superTypes:[.A; kotlin.CharSequence] + $this: VALUE_PARAMETER INSTANCE_RECEIVER name: type:.A.B + CONSTRUCTOR visibility:public <> (c:kotlin.CharSequence) returnType:.A.B [primary] + VALUE_PARAMETER name:c index:0 type:kotlin.CharSequence + BLOCK_BODY + DELEGATING_CONSTRUCTOR_CALL 'protected constructor () [primary] declared in .A' + INSTANCE_INITIALIZER_CALL classDescriptor='CLASS CLASS name:B modality:FINAL visibility:public [data] superTypes:[.A; kotlin.CharSequence]' + FUN DELEGATED_MEMBER name:get visibility:public modality:OPEN <> ($this:.A.B, index:kotlin.Int) returnType:kotlin.Char [operator] + overridden: + public abstract fun get (index: kotlin.Int): kotlin.Char [operator] declared in kotlin.CharSequence + $this: VALUE_PARAMETER name: type:.A.B + VALUE_PARAMETER name:index index:0 type:kotlin.Int + BLOCK_BODY + RETURN type=kotlin.Nothing from='public open fun get (index: kotlin.Int): kotlin.Char [operator] declared in .A.B' + CALL 'public abstract fun get (index: kotlin.Int): kotlin.Char [operator] declared in kotlin.CharSequence' type=kotlin.Char origin=null + $this: GET_FIELD 'FIELD PROPERTY_BACKING_FIELD name:c type:kotlin.CharSequence visibility:private [final]' type=kotlin.CharSequence origin=null + receiver: GET_VAR ': .A.B declared in .A.B.get' type=.A.B origin=null + index: GET_VAR 'index: kotlin.Int declared in .A.B.get' type=kotlin.Int origin=null + FUN DELEGATED_MEMBER name:subSequence visibility:public modality:OPEN <> ($this:.A.B, startIndex:kotlin.Int, endIndex:kotlin.Int) returnType:kotlin.CharSequence + overridden: + public abstract fun subSequence (startIndex: kotlin.Int, endIndex: kotlin.Int): kotlin.CharSequence declared in kotlin.CharSequence + $this: VALUE_PARAMETER name: type:.A.B + VALUE_PARAMETER name:startIndex index:0 type:kotlin.Int + VALUE_PARAMETER name:endIndex index:1 type:kotlin.Int + BLOCK_BODY + RETURN type=kotlin.Nothing from='public open fun subSequence (startIndex: kotlin.Int, endIndex: kotlin.Int): kotlin.CharSequence declared in .A.B' + CALL 'public abstract fun subSequence (startIndex: kotlin.Int, endIndex: kotlin.Int): kotlin.CharSequence declared in kotlin.CharSequence' type=kotlin.CharSequence origin=null + $this: GET_FIELD 'FIELD PROPERTY_BACKING_FIELD name:c type:kotlin.CharSequence visibility:private [final]' type=kotlin.CharSequence origin=null + receiver: GET_VAR ': .A.B declared in .A.B.subSequence' type=.A.B origin=null + startIndex: GET_VAR 'startIndex: kotlin.Int declared in .A.B.subSequence' type=kotlin.Int origin=null + endIndex: GET_VAR 'endIndex: kotlin.Int declared in .A.B.subSequence' type=kotlin.Int origin=null + PROPERTY DELEGATED_MEMBER name:length visibility:public modality:OPEN [val] + overridden: + public abstract length: kotlin.Int [val] + FUN DELEGATED_MEMBER name: visibility:public modality:OPEN <> ($this:.A.B) returnType:kotlin.Int + correspondingProperty: PROPERTY DELEGATED_MEMBER name:length visibility:public modality:OPEN [val] + overridden: + public abstract fun (): kotlin.Int declared in kotlin.CharSequence + $this: VALUE_PARAMETER name: type:.A.B + BLOCK_BODY + RETURN type=kotlin.Nothing from='public open fun (): kotlin.Int declared in .A.B' + CALL 'public abstract fun (): kotlin.Int declared in kotlin.CharSequence' type=kotlin.Int origin=null + $this: GET_FIELD 'FIELD PROPERTY_BACKING_FIELD name:c type:kotlin.CharSequence visibility:private [final]' type=kotlin.CharSequence origin=null + receiver: GET_VAR ': .A.B declared in .A.B.' type=.A.B origin=null + PROPERTY name:c visibility:public modality:FINAL [val] + FIELD PROPERTY_BACKING_FIELD name:c type:kotlin.CharSequence visibility:private [final] + EXPRESSION_BODY + GET_VAR 'c: kotlin.CharSequence declared in .A.B.' type=kotlin.CharSequence origin=INITIALIZE_PROPERTY_FROM_PARAMETER + FUN DEFAULT_PROPERTY_ACCESSOR name: visibility:public modality:FINAL <> ($this:.A.B) returnType:kotlin.CharSequence + correspondingProperty: PROPERTY name:c visibility:public modality:FINAL [val] + $this: VALUE_PARAMETER name: type:.A.B + BLOCK_BODY + RETURN type=kotlin.Nothing from='public final fun (): kotlin.CharSequence declared in .A.B' + GET_FIELD 'FIELD PROPERTY_BACKING_FIELD name:c type:kotlin.CharSequence visibility:private [final]' type=kotlin.CharSequence origin=null + receiver: GET_VAR ': .A.B declared in .A.B.' type=.A.B origin=null + FUN name:component1 visibility:public modality:FINAL <> ($this:.A.B) returnType:kotlin.CharSequence [operator] + $this: VALUE_PARAMETER name: type:.A.B + BLOCK_BODY + RETURN type=kotlin.Nothing from='public final fun component1 (): kotlin.CharSequence [operator] declared in .A.B' + GET_FIELD 'FIELD PROPERTY_BACKING_FIELD name:c type:kotlin.CharSequence visibility:private [final]' type=kotlin.CharSequence origin=null + receiver: GET_VAR ': .A.B declared in .A.B.component1' type=.A.B origin=null + FUN name:copy visibility:public modality:FINAL <> ($this:.A.B, c:kotlin.CharSequence) returnType:.A.B + $this: VALUE_PARAMETER name: type:.A.B + VALUE_PARAMETER name:c index:0 type:kotlin.CharSequence + EXPRESSION_BODY + GET_FIELD 'FIELD PROPERTY_BACKING_FIELD name:c type:kotlin.CharSequence visibility:private [final]' type=kotlin.CharSequence origin=null + receiver: GET_VAR ': .A.B declared in .A.B.copy' type=.A.B origin=null + BLOCK_BODY + RETURN type=kotlin.Nothing from='public final fun copy (c: kotlin.CharSequence): .A.B declared in .A.B' + CONSTRUCTOR_CALL 'public constructor (c: kotlin.CharSequence) [primary] declared in .A.B' type=.A.B origin=null + c: GET_VAR 'c: kotlin.CharSequence declared in .A.B.copy' type=kotlin.CharSequence origin=null + FUN GENERATED_DATA_CLASS_MEMBER name:equals visibility:public modality:OPEN <> ($this:.A.B, other:kotlin.Any?) returnType:kotlin.Boolean + overridden: + public open fun equals (other: kotlin.Any?): kotlin.Boolean [operator] declared in kotlin.Any + $this: VALUE_PARAMETER GENERATED_DATA_CLASS_MEMBER name: type:.A.B + VALUE_PARAMETER GENERATED_DATA_CLASS_MEMBER 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 ': .A.B declared in .A.B.equals' type=.A.B origin=null + arg1: GET_VAR 'other: kotlin.Any? declared in .A.B.equals' type=kotlin.Any? origin=null + then: RETURN type=kotlin.Nothing from='public open fun equals (other: kotlin.Any?): kotlin.Boolean declared in .A.B' + CONST Boolean type=kotlin.Boolean value=true + WHEN type=kotlin.Unit origin=null + BRANCH + if: TYPE_OP type=kotlin.Boolean origin=NOT_INSTANCEOF typeOperand=.A.B + GET_VAR 'other: kotlin.Any? declared in .A.B.equals' type=kotlin.Any? origin=null + then: RETURN type=kotlin.Nothing from='public open fun equals (other: kotlin.Any?): kotlin.Boolean declared in .A.B' + CONST Boolean type=kotlin.Boolean value=false + VAR IR_TEMPORARY_VARIABLE name:tmp_0 type:.A.B [val] + TYPE_OP type=.A.B origin=CAST typeOperand=.A.B + GET_VAR 'other: kotlin.Any? declared in .A.B.equals' type=kotlin.Any? origin=null + WHEN type=kotlin.Unit origin=null + BRANCH + if: CALL 'public final fun not (): kotlin.Boolean [operator] 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:c type:kotlin.CharSequence visibility:private [final]' type=kotlin.CharSequence origin=null + receiver: GET_VAR ': .A.B declared in .A.B.equals' type=.A.B origin=null + arg1: GET_FIELD 'FIELD PROPERTY_BACKING_FIELD name:c type:kotlin.CharSequence visibility:private [final]' type=kotlin.CharSequence origin=null + receiver: GET_VAR 'val tmp_0: .A.B [val] declared in .A.B.equals' type=.A.B origin=null + then: RETURN type=kotlin.Nothing from='public open fun equals (other: kotlin.Any?): kotlin.Boolean declared in .A.B' + CONST Boolean type=kotlin.Boolean value=false + RETURN type=kotlin.Nothing from='public open fun equals (other: kotlin.Any?): kotlin.Boolean declared in .A.B' + CONST Boolean type=kotlin.Boolean value=true + FUN GENERATED_DATA_CLASS_MEMBER name:hashCode visibility:public modality:OPEN <> ($this:.A.B) returnType:kotlin.Int + overridden: + public open fun hashCode (): kotlin.Int declared in kotlin.Any + $this: VALUE_PARAMETER GENERATED_DATA_CLASS_MEMBER name: type:.A.B + BLOCK_BODY + RETURN type=kotlin.Nothing from='public open fun hashCode (): kotlin.Int declared in .A.B' + CALL 'public open fun hashCode (): kotlin.Int [fake_override] declared in kotlin.CharSequence' type=kotlin.Int origin=null + $this: GET_FIELD 'FIELD PROPERTY_BACKING_FIELD name:c type:kotlin.CharSequence visibility:private [final]' type=kotlin.CharSequence origin=null + receiver: GET_VAR ': .A.B declared in .A.B.hashCode' type=.A.B origin=null + FUN GENERATED_DATA_CLASS_MEMBER name:toString visibility:public modality:OPEN <> ($this:.A.B) returnType:kotlin.String + overridden: + public open fun toString (): kotlin.String declared in kotlin.Any + $this: VALUE_PARAMETER GENERATED_DATA_CLASS_MEMBER name: type:.A.B + BLOCK_BODY + RETURN type=kotlin.Nothing from='public open fun toString (): kotlin.String declared in .A.B' + STRING_CONCATENATION type=kotlin.String + CONST String type=kotlin.String value="B(" + CONST String type=kotlin.String value="c=" + GET_FIELD 'FIELD PROPERTY_BACKING_FIELD name:c type:kotlin.CharSequence visibility:private [final]' type=kotlin.CharSequence origin=null + receiver: GET_VAR ': .A.B declared in .A.B.toString' type=.A.B origin=null + CONST String type=kotlin.String value=")" + FUN FAKE_OVERRIDE name:get visibility:public modality:ABSTRACT <> ($this:kotlin.CharSequence, index:kotlin.Int) returnType:kotlin.Char [fake_override,operator] + overridden: + public abstract fun get (index: kotlin.Int): kotlin.Char [operator] declared in kotlin.CharSequence + $this: VALUE_PARAMETER name: type:kotlin.CharSequence + VALUE_PARAMETER name:index index:0 type:kotlin.Int + FUN FAKE_OVERRIDE name:subSequence visibility:public modality:ABSTRACT <> ($this:kotlin.CharSequence, startIndex:kotlin.Int, endIndex:kotlin.Int) returnType:kotlin.CharSequence [fake_override] + overridden: + public abstract fun subSequence (startIndex: kotlin.Int, endIndex: kotlin.Int): kotlin.CharSequence declared in kotlin.CharSequence + $this: VALUE_PARAMETER name: type:kotlin.CharSequence + VALUE_PARAMETER name:startIndex index:0 type:kotlin.Int + VALUE_PARAMETER name:endIndex index:1 type:kotlin.Int + PROPERTY FAKE_OVERRIDE name:length visibility:public modality:ABSTRACT [fake_override,val] + overridden: + public abstract length: kotlin.Int [val] + FUN FAKE_OVERRIDE name: visibility:public modality:ABSTRACT <> ($this:kotlin.CharSequence) returnType:kotlin.Int [fake_override] + correspondingProperty: PROPERTY FAKE_OVERRIDE name:length visibility:public modality:ABSTRACT [fake_override,val] + overridden: + public abstract fun (): kotlin.Int declared in kotlin.CharSequence + $this: VALUE_PARAMETER name: type:kotlin.CharSequence + FUN FAKE_OVERRIDE name:equals visibility:public modality:OPEN <> ($this:kotlin.Any, other:kotlin.Any?) returnType:kotlin.Boolean [fake_override,operator] + overridden: + public open fun equals (other: kotlin.Any?): kotlin.Boolean [fake_override,operator] declared in kotlin.CharSequence + $this: VALUE_PARAMETER name: type:kotlin.Any + VALUE_PARAMETER name:other index:0 type:kotlin.Any? + FUN FAKE_OVERRIDE name:hashCode visibility:public modality:OPEN <> ($this:kotlin.Any) returnType:kotlin.Int [fake_override] + overridden: + public open fun hashCode (): kotlin.Int [fake_override] declared in kotlin.CharSequence + $this: VALUE_PARAMETER name: type:kotlin.Any + FUN FAKE_OVERRIDE name:toString visibility:public modality:OPEN <> ($this:kotlin.Any) returnType:kotlin.String [fake_override] + overridden: + public open fun toString (): kotlin.String [fake_override] declared in kotlin.CharSequence + $this: VALUE_PARAMETER name: type:kotlin.Any diff --git a/compiler/testData/ir/irText/classes/dataClasses/delegationInSealed.fir.kt.txt b/compiler/testData/ir/irText/classes/dataClasses/delegationInSealed.fir.kt.txt new file mode 100644 index 00000000000..a23ac789b18 --- /dev/null +++ b/compiler/testData/ir/irText/classes/dataClasses/delegationInSealed.fir.kt.txt @@ -0,0 +1,64 @@ +sealed class A : CharSequence { + protected constructor() /* primary */ { + super/*Any*/() + /* () */ + + } + + data class B : A, CharSequence { + constructor(c: CharSequence) /* primary */ { + super/*A*/() + /* () */ + + } + + override operator fun get(index: Int): Char { + return .#c.get(index = index) + } + + override fun subSequence(startIndex: Int, endIndex: Int): CharSequence { + return .#c.subSequence(startIndex = startIndex, endIndex = endIndex) + } + + override val length: Int + override get(): Int { + return .#c.() + } + + val c: CharSequence + field = c + get + + operator fun component1(): CharSequence { + return .#c + } + + fun copy(c: CharSequence = .#c): B { + return B(c = c) + } + + override fun equals(other: Any?): Boolean { + when { + EQEQEQ(arg0 = , arg1 = other) -> return true + } + when { + other !is B -> return false + } + val tmp0_other_with_cast: B = other as B + when { + EQEQ(arg0 = .#c, arg1 = tmp0_other_with_cast.#c).not() -> return false + } + return true + } + + override fun hashCode(): Int { + return .#c.hashCode() + } + + override fun toString(): String { + return "B(" + "c=" + .#c + ")" + } + + } + +} diff --git a/compiler/testData/ir/irText/classes/dataClasses/delegationInSealed.ir.txt b/compiler/testData/ir/irText/classes/dataClasses/delegationInSealed.ir.txt new file mode 100644 index 00000000000..ead7d656162 --- /dev/null +++ b/compiler/testData/ir/irText/classes/dataClasses/delegationInSealed.ir.txt @@ -0,0 +1,174 @@ +FILE fqName: fileName:/delegationInSealed.kt + CLASS CLASS name:A modality:SEALED visibility:public superTypes:[kotlin.CharSequence] + sealedSubclasses: + CLASS CLASS name:B modality:FINAL visibility:public [data] superTypes:[.A; kotlin.CharSequence] + $this: VALUE_PARAMETER INSTANCE_RECEIVER name: type:.A + CONSTRUCTOR visibility:protected <> () returnType:.A [primary] + BLOCK_BODY + DELEGATING_CONSTRUCTOR_CALL 'public constructor () [primary] declared in kotlin.Any' + INSTANCE_INITIALIZER_CALL classDescriptor='CLASS CLASS name:A modality:SEALED visibility:public superTypes:[kotlin.CharSequence]' + CLASS CLASS name:B modality:FINAL visibility:public [data] superTypes:[.A; kotlin.CharSequence] + $this: VALUE_PARAMETER INSTANCE_RECEIVER name: type:.A.B + CONSTRUCTOR visibility:public <> (c:kotlin.CharSequence) returnType:.A.B [primary] + VALUE_PARAMETER name:c index:0 type:kotlin.CharSequence + BLOCK_BODY + DELEGATING_CONSTRUCTOR_CALL 'protected constructor () [primary] declared in .A' + INSTANCE_INITIALIZER_CALL classDescriptor='CLASS CLASS name:B modality:FINAL visibility:public [data] superTypes:[.A; kotlin.CharSequence]' + PROPERTY name:c visibility:public modality:FINAL [val] + FIELD PROPERTY_BACKING_FIELD name:c type:kotlin.CharSequence visibility:private [final] + EXPRESSION_BODY + GET_VAR 'c: kotlin.CharSequence declared in .A.B.' type=kotlin.CharSequence origin=INITIALIZE_PROPERTY_FROM_PARAMETER + FUN DEFAULT_PROPERTY_ACCESSOR name: visibility:public modality:FINAL <> ($this:.A.B) returnType:kotlin.CharSequence + correspondingProperty: PROPERTY name:c visibility:public modality:FINAL [val] + $this: VALUE_PARAMETER name: type:.A.B + BLOCK_BODY + RETURN type=kotlin.Nothing from='public final fun (): kotlin.CharSequence declared in .A.B' + GET_FIELD 'FIELD PROPERTY_BACKING_FIELD name:c type:kotlin.CharSequence visibility:private [final]' type=kotlin.CharSequence origin=null + receiver: GET_VAR ': .A.B declared in .A.B.' type=.A.B origin=null + PROPERTY DELEGATED_MEMBER name:length visibility:public modality:OPEN [val] + overridden: + public abstract length: kotlin.Int [fake_override,val] + public abstract length: kotlin.Int [val] + FUN DELEGATED_MEMBER name: visibility:public modality:OPEN <> ($this:.A.B) returnType:kotlin.Int + correspondingProperty: PROPERTY DELEGATED_MEMBER name:length visibility:public modality:OPEN [val] + overridden: + public abstract fun (): kotlin.Int [fake_override] declared in .A + public abstract fun (): kotlin.Int declared in kotlin.CharSequence + $this: VALUE_PARAMETER name: type:.A.B + BLOCK_BODY + RETURN type=kotlin.Nothing from='public open fun (): kotlin.Int declared in .A.B' + CALL 'public abstract fun (): kotlin.Int declared in kotlin.CharSequence' type=kotlin.Int origin=null + $this: GET_FIELD 'FIELD PROPERTY_BACKING_FIELD name:c type:kotlin.CharSequence visibility:private [final]' type=kotlin.CharSequence origin=null + receiver: GET_VAR ': .A.B declared in .A.B.' type=.A.B origin=null + FUN DELEGATED_MEMBER name:get visibility:public modality:OPEN <> ($this:.A.B, index:kotlin.Int) returnType:kotlin.Char [operator] + overridden: + public abstract fun get (index: kotlin.Int): kotlin.Char [fake_override,operator] declared in .A + public abstract fun get (index: kotlin.Int): kotlin.Char [operator] declared in kotlin.CharSequence + $this: VALUE_PARAMETER name: type:.A.B + VALUE_PARAMETER name:index index:0 type:kotlin.Int + BLOCK_BODY + RETURN type=kotlin.Nothing from='public open fun get (index: kotlin.Int): kotlin.Char [operator] declared in .A.B' + CALL 'public abstract fun get (index: kotlin.Int): kotlin.Char [operator] declared in kotlin.CharSequence' type=kotlin.Char origin=null + $this: GET_FIELD 'FIELD PROPERTY_BACKING_FIELD name:c type:kotlin.CharSequence visibility:private [final]' type=kotlin.CharSequence origin=null + receiver: GET_VAR ': .A.B declared in .A.B.get' type=.A.B origin=null + index: GET_VAR 'index: kotlin.Int declared in .A.B.get' type=kotlin.Int origin=null + FUN DELEGATED_MEMBER name:subSequence visibility:public modality:OPEN <> ($this:.A.B, startIndex:kotlin.Int, endIndex:kotlin.Int) returnType:kotlin.CharSequence + overridden: + public abstract fun subSequence (startIndex: kotlin.Int, endIndex: kotlin.Int): kotlin.CharSequence [fake_override] declared in .A + public abstract fun subSequence (startIndex: kotlin.Int, endIndex: kotlin.Int): kotlin.CharSequence declared in kotlin.CharSequence + $this: VALUE_PARAMETER name: type:.A.B + VALUE_PARAMETER name:startIndex index:0 type:kotlin.Int + VALUE_PARAMETER name:endIndex index:1 type:kotlin.Int + BLOCK_BODY + RETURN type=kotlin.Nothing from='public open fun subSequence (startIndex: kotlin.Int, endIndex: kotlin.Int): kotlin.CharSequence declared in .A.B' + CALL 'public abstract fun subSequence (startIndex: kotlin.Int, endIndex: kotlin.Int): kotlin.CharSequence declared in kotlin.CharSequence' type=kotlin.CharSequence origin=null + $this: GET_FIELD 'FIELD PROPERTY_BACKING_FIELD name:c type:kotlin.CharSequence visibility:private [final]' type=kotlin.CharSequence origin=null + receiver: GET_VAR ': .A.B declared in .A.B.subSequence' type=.A.B origin=null + startIndex: GET_VAR 'startIndex: kotlin.Int declared in .A.B.subSequence' type=kotlin.Int origin=null + endIndex: GET_VAR 'endIndex: kotlin.Int declared in .A.B.subSequence' type=kotlin.Int origin=null + FUN GENERATED_DATA_CLASS_MEMBER name:component1 visibility:public modality:FINAL <> ($this:.A.B) returnType:kotlin.CharSequence [operator] + $this: VALUE_PARAMETER name: type:.A.B + BLOCK_BODY + RETURN type=kotlin.Nothing from='public final fun component1 (): kotlin.CharSequence [operator] declared in .A.B' + GET_FIELD 'FIELD PROPERTY_BACKING_FIELD name:c type:kotlin.CharSequence visibility:private [final]' type=kotlin.CharSequence origin=null + receiver: GET_VAR ': .A.B declared in .A.B.component1' type=.A.B origin=null + FUN GENERATED_DATA_CLASS_MEMBER name:copy visibility:public modality:FINAL <> ($this:.A.B, c:kotlin.CharSequence) returnType:.A.B + $this: VALUE_PARAMETER name: type:.A.B + VALUE_PARAMETER name:c index:0 type:kotlin.CharSequence + EXPRESSION_BODY + GET_FIELD 'FIELD PROPERTY_BACKING_FIELD name:c type:kotlin.CharSequence visibility:private [final]' type=kotlin.CharSequence origin=null + receiver: GET_VAR ': .A.B declared in .A.B.copy' type=.A.B origin=null + BLOCK_BODY + RETURN type=kotlin.Nothing from='public final fun copy (c: kotlin.CharSequence): .A.B declared in .A.B' + CONSTRUCTOR_CALL 'public constructor (c: kotlin.CharSequence) [primary] declared in .A.B' type=.A.B origin=null + c: GET_VAR 'c: kotlin.CharSequence declared in .A.B.copy' type=kotlin.CharSequence origin=null + FUN GENERATED_DATA_CLASS_MEMBER name:toString visibility:public modality:OPEN <> ($this:.A.B) returnType:kotlin.String + overridden: + public open fun toString (): kotlin.String [fake_override] declared in .A + public open fun toString (): kotlin.String [fake_override] declared in kotlin.CharSequence + $this: VALUE_PARAMETER name: type:.A.B + BLOCK_BODY + RETURN type=kotlin.Nothing from='public open fun toString (): kotlin.String declared in .A.B' + STRING_CONCATENATION type=kotlin.String + CONST String type=kotlin.String value="B(" + CONST String type=kotlin.String value="c=" + GET_FIELD 'FIELD PROPERTY_BACKING_FIELD name:c type:kotlin.CharSequence visibility:private [final]' type=kotlin.CharSequence origin=null + receiver: GET_VAR ': .A.B declared in .A.B.toString' type=.A.B origin=null + CONST String type=kotlin.String value=")" + FUN GENERATED_DATA_CLASS_MEMBER name:hashCode visibility:public modality:OPEN <> ($this:.A.B) returnType:kotlin.Int + overridden: + public open fun hashCode (): kotlin.Int [fake_override] declared in .A + public open fun hashCode (): kotlin.Int [fake_override] declared in kotlin.CharSequence + $this: VALUE_PARAMETER name: type:.A.B + BLOCK_BODY + RETURN type=kotlin.Nothing from='public open fun hashCode (): kotlin.Int declared in .A.B' + CALL 'public open fun hashCode (): kotlin.Int [fake_override] declared in kotlin.CharSequence' type=kotlin.Int origin=null + $this: GET_FIELD 'FIELD PROPERTY_BACKING_FIELD name:c type:kotlin.CharSequence visibility:private [final]' type=kotlin.CharSequence origin=null + receiver: GET_VAR ': .A.B declared in .A.B.hashCode' type=.A.B origin=null + FUN GENERATED_DATA_CLASS_MEMBER name:equals visibility:public modality:OPEN <> ($this:.A.B, other:kotlin.Any?) returnType:kotlin.Boolean [operator] + overridden: + public open fun equals (other: kotlin.Any?): kotlin.Boolean [fake_override,operator] declared in .A + public open fun equals (other: kotlin.Any?): kotlin.Boolean [fake_override,operator] declared in kotlin.CharSequence + $this: VALUE_PARAMETER name: type:.A.B + 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 ': .A.B declared in .A.B.equals' type=.A.B origin=null + arg1: GET_VAR 'other: kotlin.Any? declared in .A.B.equals' type=kotlin.Any? origin=null + then: RETURN type=kotlin.Nothing from='public open fun equals (other: kotlin.Any?): kotlin.Boolean [operator] declared in .A.B' + CONST Boolean type=kotlin.Boolean value=true + WHEN type=kotlin.Unit origin=null + BRANCH + if: TYPE_OP type=kotlin.Boolean origin=NOT_INSTANCEOF typeOperand=.A.B + GET_VAR 'other: kotlin.Any? declared in .A.B.equals' type=kotlin.Any? origin=null + then: RETURN type=kotlin.Nothing from='public open fun equals (other: kotlin.Any?): kotlin.Boolean [operator] declared in .A.B' + CONST Boolean type=kotlin.Boolean value=false + VAR IR_TEMPORARY_VARIABLE name:tmp_0 type:.A.B [val] + TYPE_OP type=.A.B origin=CAST typeOperand=.A.B + GET_VAR 'other: kotlin.Any? declared in .A.B.equals' type=kotlin.Any? origin=null + WHEN type=kotlin.Unit origin=null + BRANCH + if: CALL 'public final fun not (): kotlin.Boolean [operator] 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:c type:kotlin.CharSequence visibility:private [final]' type=kotlin.CharSequence origin=null + receiver: GET_VAR ': .A.B declared in .A.B.equals' type=.A.B origin=null + arg1: GET_FIELD 'FIELD PROPERTY_BACKING_FIELD name:c type:kotlin.CharSequence visibility:private [final]' type=kotlin.CharSequence origin=null + receiver: GET_VAR 'val tmp_0: .A.B [val] declared in .A.B.equals' type=.A.B origin=null + then: RETURN type=kotlin.Nothing from='public open fun equals (other: kotlin.Any?): kotlin.Boolean [operator] declared in .A.B' + CONST Boolean type=kotlin.Boolean value=false + RETURN type=kotlin.Nothing from='public open fun equals (other: kotlin.Any?): kotlin.Boolean [operator] declared in .A.B' + CONST Boolean type=kotlin.Boolean value=true + PROPERTY FAKE_OVERRIDE name:length visibility:public modality:ABSTRACT [fake_override,val] + overridden: + public abstract length: kotlin.Int [val] + FUN FAKE_OVERRIDE name: visibility:public modality:ABSTRACT <> ($this:kotlin.CharSequence) returnType:kotlin.Int [fake_override] + correspondingProperty: PROPERTY FAKE_OVERRIDE name:length visibility:public modality:ABSTRACT [fake_override,val] + overridden: + public abstract fun (): kotlin.Int declared in kotlin.CharSequence + $this: VALUE_PARAMETER name: type:kotlin.CharSequence + FUN FAKE_OVERRIDE name:equals visibility:public modality:OPEN <> ($this:kotlin.Any, other:kotlin.Any?) returnType:kotlin.Boolean [fake_override,operator] + overridden: + public open fun equals (other: kotlin.Any?): kotlin.Boolean [fake_override,operator] declared in kotlin.CharSequence + $this: VALUE_PARAMETER name: type:kotlin.Any + VALUE_PARAMETER name:other index:0 type:kotlin.Any? + FUN FAKE_OVERRIDE name:get visibility:public modality:ABSTRACT <> ($this:kotlin.CharSequence, index:kotlin.Int) returnType:kotlin.Char [fake_override,operator] + overridden: + public abstract fun get (index: kotlin.Int): kotlin.Char [operator] declared in kotlin.CharSequence + $this: VALUE_PARAMETER name: type:kotlin.CharSequence + VALUE_PARAMETER name:index index:0 type:kotlin.Int + FUN FAKE_OVERRIDE name:hashCode visibility:public modality:OPEN <> ($this:kotlin.Any) returnType:kotlin.Int [fake_override] + overridden: + public open fun hashCode (): kotlin.Int [fake_override] declared in kotlin.CharSequence + $this: VALUE_PARAMETER name: type:kotlin.Any + FUN FAKE_OVERRIDE name:subSequence visibility:public modality:ABSTRACT <> ($this:kotlin.CharSequence, startIndex:kotlin.Int, endIndex:kotlin.Int) returnType:kotlin.CharSequence [fake_override] + overridden: + public abstract fun subSequence (startIndex: kotlin.Int, endIndex: kotlin.Int): kotlin.CharSequence declared in kotlin.CharSequence + $this: VALUE_PARAMETER name: type:kotlin.CharSequence + VALUE_PARAMETER name:startIndex index:0 type:kotlin.Int + VALUE_PARAMETER name:endIndex index:1 type:kotlin.Int + FUN FAKE_OVERRIDE name:toString visibility:public modality:OPEN <> ($this:kotlin.Any) returnType:kotlin.String [fake_override] + overridden: + public open fun toString (): kotlin.String [fake_override] declared in kotlin.CharSequence + $this: VALUE_PARAMETER name: type:kotlin.Any diff --git a/compiler/testData/ir/irText/classes/dataClasses/delegationInSealed.kt b/compiler/testData/ir/irText/classes/dataClasses/delegationInSealed.kt new file mode 100644 index 00000000000..b59f1d58e8d --- /dev/null +++ b/compiler/testData/ir/irText/classes/dataClasses/delegationInSealed.kt @@ -0,0 +1,6 @@ +// WITH_STDLIB +// SKIP_KLIB_TEST + +sealed class A : CharSequence { + data class B(val c: CharSequence) : A(), CharSequence by c +} diff --git a/compiler/testData/ir/irText/classes/dataClasses/delegationInSealed.kt.txt b/compiler/testData/ir/irText/classes/dataClasses/delegationInSealed.kt.txt new file mode 100644 index 00000000000..b9871ca2017 --- /dev/null +++ b/compiler/testData/ir/irText/classes/dataClasses/delegationInSealed.kt.txt @@ -0,0 +1,64 @@ +sealed class A : CharSequence { + protected constructor() /* primary */ { + super/*Any*/() + /* () */ + + } + + data class B : A, CharSequence { + constructor(c: CharSequence) /* primary */ { + super/*A*/() + /* () */ + + } + + val c: CharSequence + field = c + get + + override val length: Int + override get(): Int { + return .#c.() + } + + override operator fun get(index: Int): Char { + return .#c.get(index = index) + } + + override fun subSequence(startIndex: Int, endIndex: Int): CharSequence { + return .#c.subSequence(startIndex = startIndex, endIndex = endIndex) + } + + operator fun component1(): CharSequence { + return .#c + } + + fun copy(c: CharSequence = .#c): B { + return B(c = c) + } + + override fun toString(): String { + return "B(" + "c=" + .#c + ")" + } + + override fun hashCode(): Int { + return .#c.hashCode() + } + + override operator fun equals(other: Any?): Boolean { + when { + EQEQEQ(arg0 = , arg1 = other) -> return true + } + when { + other !is B -> return false + } + val tmp0_other_with_cast: B = other as B + when { + EQEQ(arg0 = .#c, arg1 = tmp0_other_with_cast.#c).not() -> return false + } + return true + } + + } + +} diff --git a/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/codegen/IrBlackBoxCodegenTestGenerated.java b/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/codegen/IrBlackBoxCodegenTestGenerated.java index e5d6fba6450..53a9993eee5 100644 --- a/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/codegen/IrBlackBoxCodegenTestGenerated.java +++ b/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/codegen/IrBlackBoxCodegenTestGenerated.java @@ -15229,6 +15229,12 @@ public class IrBlackBoxCodegenTestGenerated extends AbstractIrBlackBoxCodegenTes runTest("compiler/testData/codegen/box/delegation/mixed.kt"); } + @Test + @TestMetadata("sealedClass.kt") + public void testSealedClass() throws Exception { + runTest("compiler/testData/codegen/box/delegation/sealedClass.kt"); + } + @Test @TestMetadata("simple.kt") public void testSimple() throws Exception { diff --git a/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/ir/IrTextTestGenerated.java b/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/ir/IrTextTestGenerated.java index 3b5f1c9a72e..bae533dc833 100644 --- a/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/ir/IrTextTestGenerated.java +++ b/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/ir/IrTextTestGenerated.java @@ -337,6 +337,12 @@ public class IrTextTestGenerated extends AbstractIrTextTest { runTest("compiler/testData/ir/irText/classes/dataClasses/dataClassesGeneric.kt"); } + @Test + @TestMetadata("delegationInSealed.kt") + public void testDelegationInSealed() throws Exception { + runTest("compiler/testData/ir/irText/classes/dataClasses/delegationInSealed.kt"); + } + @Test @TestMetadata("kt31649.kt") public void testKt31649() throws Exception { diff --git a/compiler/tests-gen/org/jetbrains/kotlin/klib/KlibTextTestCaseGenerated.java b/compiler/tests-gen/org/jetbrains/kotlin/klib/KlibTextTestCaseGenerated.java index b1cfe5f5c5f..e979d167d9a 100644 --- a/compiler/tests-gen/org/jetbrains/kotlin/klib/KlibTextTestCaseGenerated.java +++ b/compiler/tests-gen/org/jetbrains/kotlin/klib/KlibTextTestCaseGenerated.java @@ -264,6 +264,11 @@ public class KlibTextTestCaseGenerated extends AbstractKlibTextTestCase { runTest("compiler/testData/ir/irText/classes/dataClasses/dataClassesGeneric.kt"); } + @TestMetadata("delegationInSealed.kt") + public void testDelegationInSealed() throws Exception { + runTest("compiler/testData/ir/irText/classes/dataClasses/delegationInSealed.kt"); + } + @TestMetadata("kt31649.kt") public void testKt31649() throws Exception { runTest("compiler/testData/ir/irText/classes/dataClasses/kt31649.kt");