diff --git a/compiler/fir/fir2ir/src/org/jetbrains/kotlin/fir/backend/Fir2IrVisitor.kt b/compiler/fir/fir2ir/src/org/jetbrains/kotlin/fir/backend/Fir2IrVisitor.kt index d83aac6e943..fcb9ccc9467 100644 --- a/compiler/fir/fir2ir/src/org/jetbrains/kotlin/fir/backend/Fir2IrVisitor.kt +++ b/compiler/fir/fir2ir/src/org/jetbrains/kotlin/fir/backend/Fir2IrVisitor.kt @@ -405,30 +405,14 @@ class Fir2IrVisitor( } private fun FirDelegatedConstructorCall.toIrDelegatingConstructorCall(): IrDelegatingConstructorCall? { - val constructedClassSymbol = with(typeContext) { - (constructedTypeRef as FirResolvedTypeRef).type.typeConstructor() - } as? FirClassSymbol<*> ?: return null val constructedIrType = constructedTypeRef.toIrType(this@Fir2IrVisitor.session, declarationStorage) - // TODO: find delegated constructor correctly - val classId = constructedClassSymbol.classId - var constructorSymbol: FirConstructorSymbol? = null - constructedClassSymbol.buildUseSiteMemberScope(this@Fir2IrVisitor.session, ScopeSession())!!.processFunctionsByName( - classId.shortClassName - ) { - when { - it !is FirConstructorSymbol -> { - } - arguments.size <= it.fir.valueParameters.size && constructorSymbol == null -> { - constructorSymbol = it - } - } - } - val foundConstructorSymbol = constructorSymbol ?: return null + val constructorSymbol = (this.calleeReference as? FirResolvedNamedReference)?.resolvedSymbol as? FirConstructorSymbol + ?: return null return convertWithOffsets { startOffset, endOffset -> IrDelegatingConstructorCallImpl( startOffset, endOffset, constructedIrType, - declarationStorage.getIrFunctionSymbol(foundConstructorSymbol) as IrConstructorSymbol + declarationStorage.getIrFunctionSymbol(constructorSymbol) as IrConstructorSymbol ).apply { for ((index, argument) in arguments.withIndex()) { val argumentExpression = argument.toIrExpression() diff --git a/compiler/testData/codegen/box/multifileClasses/sealedClassHierarchy.kt b/compiler/testData/codegen/box/multifileClasses/sealedClassHierarchy.kt index 9aff61d2774..38482ed9580 100644 --- a/compiler/testData/codegen/box/multifileClasses/sealedClassHierarchy.kt +++ b/compiler/testData/codegen/box/multifileClasses/sealedClassHierarchy.kt @@ -1,3 +1,4 @@ +// IGNORE_BACKEND_FIR: JVM_IR // TARGET_BACKEND: JVM // WITH_RUNTIME diff --git a/compiler/testData/codegen/box/secondaryConstructors/callFromLocalSubClass.kt b/compiler/testData/codegen/box/secondaryConstructors/callFromLocalSubClass.kt index e59a937d7bd..7a35241da3d 100644 --- a/compiler/testData/codegen/box/secondaryConstructors/callFromLocalSubClass.kt +++ b/compiler/testData/codegen/box/secondaryConstructors/callFromLocalSubClass.kt @@ -1,4 +1,3 @@ -// IGNORE_BACKEND_FIR: JVM_IR // IGNORE_BACKEND: JS fun box(): String { val z = "K" diff --git a/compiler/testData/codegen/box/secondaryConstructors/callFromPrimaryWithOptionalArgs.kt b/compiler/testData/codegen/box/secondaryConstructors/callFromPrimaryWithOptionalArgs.kt index 648f7696592..71955e44537 100644 --- a/compiler/testData/codegen/box/secondaryConstructors/callFromPrimaryWithOptionalArgs.kt +++ b/compiler/testData/codegen/box/secondaryConstructors/callFromPrimaryWithOptionalArgs.kt @@ -1,4 +1,3 @@ -// IGNORE_BACKEND_FIR: JVM_IR open class A(val result: String) { constructor(x: Int, y: Int = 99) : this("$x$y") } diff --git a/compiler/testData/codegen/box/secondaryConstructors/callFromSubClass.kt b/compiler/testData/codegen/box/secondaryConstructors/callFromSubClass.kt index c581d7919d1..7dd165dbc23 100644 --- a/compiler/testData/codegen/box/secondaryConstructors/callFromSubClass.kt +++ b/compiler/testData/codegen/box/secondaryConstructors/callFromSubClass.kt @@ -1,4 +1,3 @@ -// IGNORE_BACKEND_FIR: JVM_IR open class A(val x: String, val z: String) { constructor(z: String) : this("O", z) } diff --git a/compiler/testData/ir/irText/classes/enumWithMultipleCtors.fir.txt b/compiler/testData/ir/irText/classes/enumWithMultipleCtors.fir.txt index e2f8b72d9f1..d3fd71f6dac 100644 --- a/compiler/testData/ir/irText/classes/enumWithMultipleCtors.fir.txt +++ b/compiler/testData/ir/irText/classes/enumWithMultipleCtors.fir.txt @@ -14,7 +14,7 @@ FILE fqName: fileName:/enumWithMultipleCtors.kt $this: VALUE_PARAMETER INSTANCE_RECEIVER name: type:.A.Y CONSTRUCTOR visibility:private <> () returnType:. [primary] BLOCK_BODY - DELEGATING_CONSTRUCTOR_CALL 'private constructor (arg: kotlin.String) declared in .A' + DELEGATING_CONSTRUCTOR_CALL 'private constructor () declared in .A' INSTANCE_INITIALIZER_CALL classDescriptor='CLASS ENUM_ENTRY name:Y modality:FINAL visibility:private superTypes:[.A]' FUN name:f visibility:public modality:FINAL <> ($this:.A.Y) returnType:kotlin.String $this: VALUE_PARAMETER name: type:.A.Y @@ -29,8 +29,8 @@ FILE fqName: fileName:/enumWithMultipleCtors.kt $this: VALUE_PARAMETER INSTANCE_RECEIVER name: type:.A.Z CONSTRUCTOR visibility:private <> () returnType:. [primary] BLOCK_BODY - DELEGATING_CONSTRUCTOR_CALL 'private constructor (arg: kotlin.String) declared in .A' - arg: CONST Int type=kotlin.Int value=5 + DELEGATING_CONSTRUCTOR_CALL 'private constructor (x: kotlin.Int) declared in .A' + x: CONST Int type=kotlin.Int value=5 INSTANCE_INITIALIZER_CALL classDescriptor='CLASS ENUM_ENTRY name:Z modality:FINAL visibility:private superTypes:[.A]' PROPERTY name:prop1 visibility:public modality:FINAL [val] FIELD PROPERTY_BACKING_FIELD name:prop1 type:kotlin.String visibility:private [final] diff --git a/compiler/testData/ir/irText/classes/enumWithSecondaryCtor.fir.txt b/compiler/testData/ir/irText/classes/enumWithSecondaryCtor.fir.txt index c289c3fb2dc..7ac601574d8 100644 --- a/compiler/testData/ir/irText/classes/enumWithSecondaryCtor.fir.txt +++ b/compiler/testData/ir/irText/classes/enumWithSecondaryCtor.fir.txt @@ -22,7 +22,7 @@ FILE fqName: fileName:/enumWithSecondaryCtor.kt $this: VALUE_PARAMETER INSTANCE_RECEIVER name: type:.Test0.ZERO CONSTRUCTOR visibility:private <> () returnType:. [primary] BLOCK_BODY - DELEGATING_CONSTRUCTOR_CALL 'private constructor (x: kotlin.Int) [primary] declared in .Test0' + DELEGATING_CONSTRUCTOR_CALL 'private constructor () declared in .Test0' INSTANCE_INITIALIZER_CALL classDescriptor='CLASS ENUM_ENTRY name:ZERO modality:FINAL visibility:private superTypes:[.Test0]' CONSTRUCTOR visibility:private <> () returnType:.Test0 BLOCK_BODY @@ -92,7 +92,7 @@ FILE fqName: fileName:/enumWithSecondaryCtor.kt $this: VALUE_PARAMETER INSTANCE_RECEIVER name: type:.Test1.ZERO CONSTRUCTOR visibility:private <> () returnType:. [primary] BLOCK_BODY - DELEGATING_CONSTRUCTOR_CALL 'private constructor (x: kotlin.Int) [primary] declared in .Test1' + DELEGATING_CONSTRUCTOR_CALL 'private constructor () declared in .Test1' INSTANCE_INITIALIZER_CALL classDescriptor='CLASS ENUM_ENTRY name:ZERO modality:FINAL visibility:private superTypes:[.Test1]' ENUM_ENTRY name:ONE class: CLASS ENUM_ENTRY name:ONE modality:FINAL visibility:private superTypes:[.Test1] @@ -170,7 +170,7 @@ FILE fqName: fileName:/enumWithSecondaryCtor.kt $this: VALUE_PARAMETER INSTANCE_RECEIVER name: type:.Test2.ZERO CONSTRUCTOR visibility:private <> () returnType:. [primary] BLOCK_BODY - DELEGATING_CONSTRUCTOR_CALL 'private constructor (x: kotlin.Int) [primary] declared in .Test2' + DELEGATING_CONSTRUCTOR_CALL 'private constructor () declared in .Test2' INSTANCE_INITIALIZER_CALL classDescriptor='CLASS ENUM_ENTRY name:ZERO modality:FINAL visibility:private superTypes:[.Test2]' FUN name:foo visibility:public modality:FINAL <> ($this:.Test2.ZERO) returnType:kotlin.Unit $this: VALUE_PARAMETER name: type:.Test2.ZERO diff --git a/compiler/testData/ir/irText/declarations/multiplatform/expectedSealedClass.fir.txt b/compiler/testData/ir/irText/declarations/multiplatform/expectedSealedClass.fir.txt index 4a5d659ca64..a4092d8bc71 100644 --- a/compiler/testData/ir/irText/declarations/multiplatform/expectedSealedClass.fir.txt +++ b/compiler/testData/ir/irText/declarations/multiplatform/expectedSealedClass.fir.txt @@ -60,7 +60,7 @@ FILE fqName: fileName:/expectedSealedClass.kt $this: VALUE_PARAMETER INSTANCE_RECEIVER name: type:.Add CONSTRUCTOR visibility:public <> () returnType:.Add [primary] BLOCK_BODY - DELEGATING_CONSTRUCTOR_CALL 'private constructor () [primary] declared in .Ops' + ERROR_CALL 'Cannot find delegated constructor call' type=.Add INSTANCE_INITIALIZER_CALL classDescriptor='CLASS CLASS name:Add modality:FINAL visibility:public superTypes:[.Ops]' FUN FAKE_OVERRIDE name:equals visibility:public modality:OPEN <> ($this:kotlin.Any, other:kotlin.Any?) returnType:kotlin.Boolean [fake_override,operator] overridden: diff --git a/compiler/testData/ir/irText/expressions/thisReferenceBeforeClassDeclared.fir.txt b/compiler/testData/ir/irText/expressions/thisReferenceBeforeClassDeclared.fir.txt index 80883bbb360..bbce1d83987 100644 --- a/compiler/testData/ir/irText/expressions/thisReferenceBeforeClassDeclared.fir.txt +++ b/compiler/testData/ir/irText/expressions/thisReferenceBeforeClassDeclared.fir.txt @@ -8,8 +8,7 @@ FILE fqName: fileName:/thisReferenceBeforeClassDeclared.kt $this: VALUE_PARAMETER INSTANCE_RECEIVER name: type:.test. CONSTRUCTOR visibility:private <> () returnType:.WithCompanion [primary] BLOCK_BODY - DELEGATING_CONSTRUCTOR_CALL 'public constructor (a: .WithCompanion.Companion) [primary] declared in .WithCompanion' - a: GET_VAR ': . declared in .' type=. origin=null + ERROR_CALL 'Cannot find delegated constructor call' type=.WithCompanion INSTANCE_INITIALIZER_CALL classDescriptor='CLASS OBJECT name: modality:FINAL visibility:local superTypes:[.WithCompanion]' CONSTRUCTOR_CALL 'private constructor () [primary] declared in .test.' type=.test. origin=null VAR name:test2 type:. [val]