diff --git a/compiler/fir/fir2ir/src/org/jetbrains/kotlin/fir/backend/Fir2IrConverter.kt b/compiler/fir/fir2ir/src/org/jetbrains/kotlin/fir/backend/Fir2IrConverter.kt index 59360293aa3..f0fa3b94d29 100644 --- a/compiler/fir/fir2ir/src/org/jetbrains/kotlin/fir/backend/Fir2IrConverter.kt +++ b/compiler/fir/fir2ir/src/org/jetbrains/kotlin/fir/backend/Fir2IrConverter.kt @@ -92,18 +92,22 @@ class Fir2IrConverter( ) } val processedCallableNames = mutableSetOf() + val classes = mutableListOf() for (declaration in sortBySynthetic(anonymousObject.declarations)) { - if (declaration is FirRegularClass) { + val irDeclaration = if (declaration is FirRegularClass) { + classes += declaration registerClassAndNestedClasses(declaration, irClass) - processClassAndNestedClassHeaders(declaration) - } - val irDeclaration = processMemberDeclaration(declaration, anonymousObject, irClass) ?: continue - when (declaration) { - is FirSimpleFunction -> processedCallableNames += declaration.name - is FirProperty -> processedCallableNames += declaration.name + } else { + when (declaration) { + is FirSimpleFunction -> processedCallableNames += declaration.name + is FirProperty -> processedCallableNames += declaration.name + } + processMemberDeclaration(declaration, anonymousObject, irClass) ?: continue } irClass.declarations += irDeclaration } + classes.forEach { processClassAndNestedClassHeaders(it) } + classes.forEach { processClassMembers(it) } // Add delegated members *before* fake override generations. // Otherwise, fake overrides for delegated members, which are redundant, will be added. val realDeclarations = delegatedMembers(irClass) + anonymousObject.declarations diff --git a/compiler/fir/fir2ir/tests/org/jetbrains/kotlin/fir/Fir2IrTextTestGenerated.java b/compiler/fir/fir2ir/tests/org/jetbrains/kotlin/fir/Fir2IrTextTestGenerated.java index f226f6c6345..26c2417dd2b 100644 --- a/compiler/fir/fir2ir/tests/org/jetbrains/kotlin/fir/Fir2IrTextTestGenerated.java +++ b/compiler/fir/fir2ir/tests/org/jetbrains/kotlin/fir/Fir2IrTextTestGenerated.java @@ -1747,6 +1747,11 @@ public class Fir2IrTextTestGenerated extends AbstractFir2IrTextTest { runTest("compiler/testData/ir/irText/firProblems/FirBuilder.kt"); } + @TestMetadata("InnerClassInAnonymous.kt") + public void testInnerClassInAnonymous() throws Exception { + runTest("compiler/testData/ir/irText/firProblems/InnerClassInAnonymous.kt"); + } + @TestMetadata("putIfAbsent.kt") public void testPutIfAbsent() throws Exception { runTest("compiler/testData/ir/irText/firProblems/putIfAbsent.kt"); diff --git a/compiler/testData/ir/irText/firProblems/InnerClassInAnonymous.fir.txt b/compiler/testData/ir/irText/firProblems/InnerClassInAnonymous.fir.txt new file mode 100644 index 00000000000..b0bf9cce90a --- /dev/null +++ b/compiler/testData/ir/irText/firProblems/InnerClassInAnonymous.fir.txt @@ -0,0 +1,116 @@ +FILE fqName: fileName:/InnerClassInAnonymous.kt + FUN name:box visibility:public modality:FINAL <> () returnType:kotlin.String + BLOCK_BODY + VAR name:obj type:.box. [val] + BLOCK type=.box. origin=OBJECT_LITERAL + CLASS CLASS name: modality:FINAL visibility:local superTypes:[kotlin.Any] + $this: VALUE_PARAMETER INSTANCE_RECEIVER name: type:.box. + CONSTRUCTOR visibility:private <> () returnType:.box. [primary] + BLOCK_BODY + DELEGATING_CONSTRUCTOR_CALL 'public constructor () [primary] declared in kotlin.Any' + INSTANCE_INITIALIZER_CALL classDescriptor='CLASS CLASS name: modality:FINAL visibility:local superTypes:[kotlin.Any]' + PROPERTY name:end visibility:public modality:FINAL [val] + FIELD PROPERTY_BACKING_FIELD name:end type:kotlin.String visibility:private [final] + EXPRESSION_BODY + CONST String type=kotlin.String value="K" + FUN DEFAULT_PROPERTY_ACCESSOR name: visibility:public modality:FINAL <> ($this:.box.) returnType:kotlin.String + correspondingProperty: PROPERTY name:end visibility:public modality:FINAL [val] + $this: VALUE_PARAMETER name: type:.box. + BLOCK_BODY + RETURN type=kotlin.Nothing from='public final fun (): kotlin.String declared in .box.' + GET_FIELD 'FIELD PROPERTY_BACKING_FIELD name:end type:kotlin.String visibility:private [final]' type=kotlin.String origin=null + receiver: GET_VAR ': .box. declared in .box..' type=.box. origin=null + FUN name:foo visibility:public modality:FINAL <> ($this:.box.) returnType:kotlin.String + $this: VALUE_PARAMETER name: type:.box. + BLOCK_BODY + RETURN type=kotlin.Nothing from='public final fun foo (): kotlin.String declared in .box.' + CALL 'public final fun bar (): kotlin.String declared in .box..Some' type=kotlin.String origin=null + $this: CONSTRUCTOR_CALL 'public constructor (s: kotlin.String) [primary] declared in .box..Some' type=.box..Some origin=null + $outer: GET_VAR ': .box. declared in .box..foo' type=.box. origin=null + s: CONST String type=kotlin.String value="O" + CLASS CLASS name:Some modality:FINAL visibility:local [inner] superTypes:[.box..Base] + $this: VALUE_PARAMETER INSTANCE_RECEIVER name: type:.box..Some + CONSTRUCTOR visibility:public <> ($this:.box., s:kotlin.String) returnType:.box..Some [primary] + $outer: VALUE_PARAMETER name: type:.box. + VALUE_PARAMETER name:s index:0 type:kotlin.String + BLOCK_BODY + DELEGATING_CONSTRUCTOR_CALL 'public constructor (s: kotlin.String) [primary] declared in .box..Base' + $this: GET_VAR ': .box. declared in .box.' type=.box. origin=null + s: GET_VAR 's: kotlin.String declared in .box..Some.' type=kotlin.String origin=null + INSTANCE_INITIALIZER_CALL classDescriptor='CLASS CLASS name:Some modality:FINAL visibility:local [inner] superTypes:[.box..Base]' + FUN name:bar visibility:public modality:FINAL <> ($this:.box..Some) returnType:kotlin.String + $this: VALUE_PARAMETER name: type:.box..Some + BLOCK_BODY + RETURN type=kotlin.Nothing from='public final fun bar (): kotlin.String declared in .box..Some' + CALL 'public final fun plus (other: kotlin.Any?): kotlin.String [operator] declared in kotlin.String' type=kotlin.String origin=PLUS + $this: CALL 'public final fun (): kotlin.String declared in .box..Base' type=kotlin.String origin=GET_PROPERTY + $this: GET_VAR ': .box..Some declared in .box..Some.bar' type=.box..Some origin=null + other: CALL 'public final fun (): kotlin.String declared in .box.' type=kotlin.String origin=GET_PROPERTY + $this: GET_VAR ': .box. declared in .box.' type=.box. origin=null + PROPERTY FAKE_OVERRIDE name:s visibility:public modality:FINAL [fake_override,val] + FUN FAKE_OVERRIDE name: visibility:public modality:FINAL <> () returnType:kotlin.String [fake_override] + correspondingProperty: PROPERTY FAKE_OVERRIDE name:s visibility:public modality:FINAL [fake_override,val] + overridden: + public final fun (): kotlin.String declared in .box..Base + 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 [operator] declared in kotlin.Any + $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 declared in kotlin.Any + $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 declared in kotlin.Any + $this: VALUE_PARAMETER name: type:kotlin.Any + CLASS CLASS name:Base modality:OPEN visibility:local [inner] superTypes:[kotlin.Any] + $this: VALUE_PARAMETER INSTANCE_RECEIVER name: type:.box..Base + CONSTRUCTOR visibility:public <> ($this:.box., s:kotlin.String) returnType:.box..Base [primary] + $outer: VALUE_PARAMETER name: type:.box. + VALUE_PARAMETER name:s index:0 type:kotlin.String + BLOCK_BODY + DELEGATING_CONSTRUCTOR_CALL 'public constructor () [primary] declared in kotlin.Any' + INSTANCE_INITIALIZER_CALL classDescriptor='CLASS CLASS name:Base modality:OPEN visibility:local [inner] superTypes:[kotlin.Any]' + PROPERTY name:s visibility:public modality:FINAL [val] + FIELD PROPERTY_BACKING_FIELD name:s type:kotlin.String visibility:private [final] + EXPRESSION_BODY + GET_VAR 's: kotlin.String declared in .box..Base.' type=kotlin.String origin=INITIALIZE_PROPERTY_FROM_PARAMETER + FUN DEFAULT_PROPERTY_ACCESSOR name: visibility:public modality:FINAL <> ($this:.box..Base) returnType:kotlin.String + correspondingProperty: PROPERTY name:s visibility:public modality:FINAL [val] + $this: VALUE_PARAMETER name: type:.box..Base + BLOCK_BODY + RETURN type=kotlin.Nothing from='public final fun (): kotlin.String declared in .box..Base' + GET_FIELD 'FIELD PROPERTY_BACKING_FIELD name:s type:kotlin.String visibility:private [final]' type=kotlin.String origin=null + receiver: GET_VAR ': .box..Base declared in .box..Base.' type=.box..Base origin=null + 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 [operator] declared in kotlin.Any + $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 declared in kotlin.Any + $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 declared in kotlin.Any + $this: VALUE_PARAMETER name: type:kotlin.Any + 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 [operator] declared in kotlin.Any + $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 declared in kotlin.Any + $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 declared in kotlin.Any + $this: VALUE_PARAMETER name: type:kotlin.Any + CONSTRUCTOR_CALL 'private constructor () [primary] declared in .box.' type=.box. origin=OBJECT_LITERAL + RETURN type=kotlin.Nothing from='public final fun box (): kotlin.String declared in ' + CALL 'public final fun foo (): kotlin.String declared in .box.' type=kotlin.String origin=null + $this: GET_VAR 'val obj: .box. [val] declared in .box' type=.box. origin=null diff --git a/compiler/testData/ir/irText/firProblems/InnerClassInAnonymous.kt b/compiler/testData/ir/irText/firProblems/InnerClassInAnonymous.kt new file mode 100644 index 00000000000..770f53b50fe --- /dev/null +++ b/compiler/testData/ir/irText/firProblems/InnerClassInAnonymous.kt @@ -0,0 +1,14 @@ +fun box(): String { + val obj = object { + val end = "K" + + fun foo() = Some("O").bar() + + inner class Some(s: String) : Base(s) { + fun bar() = s + end + } + + open inner class Base(val s: String) + } + return obj.foo() +} \ No newline at end of file diff --git a/compiler/testData/ir/irText/firProblems/InnerClassInAnonymous.txt b/compiler/testData/ir/irText/firProblems/InnerClassInAnonymous.txt new file mode 100644 index 00000000000..10a472f5e2e --- /dev/null +++ b/compiler/testData/ir/irText/firProblems/InnerClassInAnonymous.txt @@ -0,0 +1,117 @@ +FILE fqName: fileName:/InnerClassInAnonymous.kt + FUN name:box visibility:public modality:FINAL <> () returnType:kotlin.String + BLOCK_BODY + VAR name:obj type:.box. [val] + BLOCK type=.box. origin=OBJECT_LITERAL + CLASS CLASS name: modality:FINAL visibility:local superTypes:[kotlin.Any] + $this: VALUE_PARAMETER INSTANCE_RECEIVER name: type:.box. + CONSTRUCTOR visibility:public <> () returnType:.box. [primary] + BLOCK_BODY + DELEGATING_CONSTRUCTOR_CALL 'public constructor () [primary] declared in kotlin.Any' + INSTANCE_INITIALIZER_CALL classDescriptor='CLASS CLASS name: modality:FINAL visibility:local superTypes:[kotlin.Any]' + PROPERTY name:end visibility:public modality:FINAL [val] + FIELD PROPERTY_BACKING_FIELD name:end type:kotlin.String visibility:private [final] + EXPRESSION_BODY + CONST String type=kotlin.String value="K" + FUN DEFAULT_PROPERTY_ACCESSOR name: visibility:public modality:FINAL <> ($this:.box.) returnType:kotlin.String + correspondingProperty: PROPERTY name:end visibility:public modality:FINAL [val] + $this: VALUE_PARAMETER name: type:.box. + BLOCK_BODY + RETURN type=kotlin.Nothing from='public final fun (): kotlin.String declared in .box.' + GET_FIELD 'FIELD PROPERTY_BACKING_FIELD name:end type:kotlin.String visibility:private [final]' type=kotlin.String origin=null + receiver: GET_VAR ': .box. declared in .box..' type=.box. origin=null + FUN name:foo visibility:public modality:FINAL <> ($this:.box.) returnType:kotlin.String + $this: VALUE_PARAMETER name: type:.box. + BLOCK_BODY + RETURN type=kotlin.Nothing from='public final fun foo (): kotlin.String declared in .box.' + CALL 'public final fun bar (): kotlin.String declared in .box..Some' type=kotlin.String origin=null + $this: CONSTRUCTOR_CALL 'public constructor (s: kotlin.String) [primary] declared in .box..Some' type=.box..Some origin=null + $outer: GET_VAR ': .box. declared in .box..foo' type=.box. origin=null + s: CONST String type=kotlin.String value="O" + CLASS CLASS name:Some modality:FINAL visibility:local [inner] superTypes:[.box..Base] + $this: VALUE_PARAMETER INSTANCE_RECEIVER name: type:.box..Some + CONSTRUCTOR visibility:public <> ($this:.box., s:kotlin.String) returnType:.box..Some [primary] + $outer: VALUE_PARAMETER name: type:.box. + VALUE_PARAMETER name:s index:0 type:kotlin.String + BLOCK_BODY + DELEGATING_CONSTRUCTOR_CALL 'public constructor (s: kotlin.String) [primary] declared in .box..Base' + $this: GET_VAR ': .box. declared in .box..Some.' type=.box. origin=null + s: GET_VAR 's: kotlin.String declared in .box..Some.' type=kotlin.String origin=null + INSTANCE_INITIALIZER_CALL classDescriptor='CLASS CLASS name:Some modality:FINAL visibility:local [inner] superTypes:[.box..Base]' + FUN name:bar visibility:public modality:FINAL <> ($this:.box..Some) returnType:kotlin.String + $this: VALUE_PARAMETER name: type:.box..Some + BLOCK_BODY + RETURN type=kotlin.Nothing from='public final fun bar (): kotlin.String declared in .box..Some' + CALL 'public final fun plus (other: kotlin.Any?): kotlin.String [operator] declared in kotlin.String' type=kotlin.String origin=PLUS + $this: CALL 'public final fun (): kotlin.String [fake_override] declared in .box..Some' type=kotlin.String origin=GET_PROPERTY + $this: GET_VAR ': .box..Some declared in .box..Some.bar' type=.box..Some origin=null + other: CALL 'public final fun (): kotlin.String declared in .box.' type=kotlin.String origin=GET_PROPERTY + $this: GET_VAR ': .box. declared in .box.' type=.box. origin=null + PROPERTY FAKE_OVERRIDE name:s visibility:public modality:FINAL [fake_override,val] + FUN FAKE_OVERRIDE name: visibility:public modality:FINAL <> ($this:.box..Base) returnType:kotlin.String [fake_override] + correspondingProperty: PROPERTY FAKE_OVERRIDE name:s visibility:public modality:FINAL [fake_override,val] + overridden: + public final fun (): kotlin.String declared in .box..Base + $this: VALUE_PARAMETER name: type:.box..Base + 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 .box..Base + $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 .box..Base + $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 .box..Base + $this: VALUE_PARAMETER name: type:kotlin.Any + CLASS CLASS name:Base modality:OPEN visibility:local [inner] superTypes:[kotlin.Any] + $this: VALUE_PARAMETER INSTANCE_RECEIVER name: type:.box..Base + CONSTRUCTOR visibility:public <> ($this:.box., s:kotlin.String) returnType:.box..Base [primary] + $outer: VALUE_PARAMETER name: type:.box. + VALUE_PARAMETER name:s index:0 type:kotlin.String + BLOCK_BODY + DELEGATING_CONSTRUCTOR_CALL 'public constructor () [primary] declared in kotlin.Any' + INSTANCE_INITIALIZER_CALL classDescriptor='CLASS CLASS name:Base modality:OPEN visibility:local [inner] superTypes:[kotlin.Any]' + PROPERTY name:s visibility:public modality:FINAL [val] + FIELD PROPERTY_BACKING_FIELD name:s type:kotlin.String visibility:private [final] + EXPRESSION_BODY + GET_VAR 's: kotlin.String declared in .box..Base.' type=kotlin.String origin=INITIALIZE_PROPERTY_FROM_PARAMETER + FUN DEFAULT_PROPERTY_ACCESSOR name: visibility:public modality:FINAL <> ($this:.box..Base) returnType:kotlin.String + correspondingProperty: PROPERTY name:s visibility:public modality:FINAL [val] + $this: VALUE_PARAMETER name: type:.box..Base + BLOCK_BODY + RETURN type=kotlin.Nothing from='public final fun (): kotlin.String declared in .box..Base' + GET_FIELD 'FIELD PROPERTY_BACKING_FIELD name:s type:kotlin.String visibility:private [final]' type=kotlin.String origin=null + receiver: GET_VAR ': .box..Base declared in .box..Base.' type=.box..Base origin=null + 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 [operator] declared in kotlin.Any + $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 declared in kotlin.Any + $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 declared in kotlin.Any + $this: VALUE_PARAMETER name: type:kotlin.Any + 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 [operator] declared in kotlin.Any + $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 declared in kotlin.Any + $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 declared in kotlin.Any + $this: VALUE_PARAMETER name: type:kotlin.Any + CONSTRUCTOR_CALL 'public constructor () [primary] declared in .box.' type=.box. origin=OBJECT_LITERAL + RETURN type=kotlin.Nothing from='public final fun box (): kotlin.String declared in ' + CALL 'public final fun foo (): kotlin.String declared in .box.' type=kotlin.String origin=null + $this: GET_VAR 'val obj: .box. [val] declared in .box' type=.box. origin=null diff --git a/compiler/tests/org/jetbrains/kotlin/ir/IrTextTestCaseGenerated.java b/compiler/tests/org/jetbrains/kotlin/ir/IrTextTestCaseGenerated.java index 4e7e08e9157..a792bf5bd3a 100644 --- a/compiler/tests/org/jetbrains/kotlin/ir/IrTextTestCaseGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/ir/IrTextTestCaseGenerated.java @@ -1746,6 +1746,11 @@ public class IrTextTestCaseGenerated extends AbstractIrTextTestCase { runTest("compiler/testData/ir/irText/firProblems/FirBuilder.kt"); } + @TestMetadata("InnerClassInAnonymous.kt") + public void testInnerClassInAnonymous() throws Exception { + runTest("compiler/testData/ir/irText/firProblems/InnerClassInAnonymous.kt"); + } + @TestMetadata("putIfAbsent.kt") public void testPutIfAbsent() throws Exception { runTest("compiler/testData/ir/irText/firProblems/putIfAbsent.kt");