From 6f0eeecc64bb425db16d847111cc1f3c62d75044 Mon Sep 17 00:00:00 2001 From: Mikhail Glukhikh Date: Mon, 8 Jun 2020 14:59:36 +0300 Subject: [PATCH] [FIR2IR] Fix generation of type arguments of delegated constructor calls --- .../backend/generators/ClassMemberGenerator.kt | 16 +++++++++------- .../testData/codegen/box/regressions/kt6485.kt | 1 - .../reified/anonymousObjectReifiedSupertype.kt | 1 - .../box/reified/approximateCapturedTypes.kt | 1 - .../codegen/box/reified/innerAnonymousObject.kt | 1 - .../box/reified/nestedReifiedSignature.kt | 1 - .../box/reified/recursiveInnerAnonymousObject.kt | 1 - ...ConstructorCallToTypeAliasConstructor.fir.txt | 3 +-- .../ir/irText/declarations/fakeOverrides.fir.txt | 2 +- .../declarations/parameters/constructor.fir.txt | 4 ++-- .../typeParameterBoundedBySubclass.fir.txt | 2 +- .../expressions/thisOfGenericOuterClass.fir.txt | 1 + .../genericClassInDifferentModule_m2.fir.txt | 2 +- .../smartCastOnFakeOverrideReceiver.fir.txt | 2 +- 14 files changed, 17 insertions(+), 21 deletions(-) diff --git a/compiler/fir/fir2ir/src/org/jetbrains/kotlin/fir/backend/generators/ClassMemberGenerator.kt b/compiler/fir/fir2ir/src/org/jetbrains/kotlin/fir/backend/generators/ClassMemberGenerator.kt index 2ff37b0a876..74d21bdf71e 100644 --- a/compiler/fir/fir2ir/src/org/jetbrains/kotlin/fir/backend/generators/ClassMemberGenerator.kt +++ b/compiler/fir/fir2ir/src/org/jetbrains/kotlin/fir/backend/generators/ClassMemberGenerator.kt @@ -259,8 +259,8 @@ internal class ClassMemberGenerator( val firDispatchReceiver = dispatchReceiver return convertWithOffsets { startOffset, endOffset -> val irConstructorSymbol = declarationStorage.getIrFunctionSymbol(constructorSymbol) as IrConstructorSymbol + val typeArguments = (constructedTypeRef as? FirResolvedTypeRef)?.type?.typeArguments if (constructorSymbol.fir.isFromEnumClass || constructorSymbol.fir.returnTypeRef.isEnum) { - val typeArguments = (constructedTypeRef as? FirResolvedTypeRef)?.type?.typeArguments IrEnumConstructorCallImpl( startOffset, endOffset, constructedIrType, @@ -268,20 +268,22 @@ internal class ClassMemberGenerator( typeArgumentsCount = typeArguments?.size ?: 0, valueArgumentsCount = constructorSymbol.fir.valueParameters.size ).apply { - if (typeArguments?.isNotEmpty() == true) { - val irType = (typeArguments.first() as ConeKotlinTypeProjection).type.toIrType() - putTypeArgument(0, irType) - } } } else { IrDelegatingConstructorCallImpl( startOffset, endOffset, constructedIrType, irConstructorSymbol, - valueArgumentsCount = irConstructorSymbol.owner.valueParameters.size, - typeArgumentsCount = irConstructorSymbol.owner.typeParameters.size + typeArgumentsCount = typeArguments?.size ?: 0, + valueArgumentsCount = irConstructorSymbol.owner.valueParameters.size ) }.let { + if (typeArguments != null) { + for ((index, typeArgument) in typeArguments.withIndex()) { + val irType = (typeArgument as ConeKotlinTypeProjection).type.toIrType() + it.putTypeArgument(index, irType) + } + } if (firDispatchReceiver !is FirNoReceiverExpression) { it.dispatchReceiver = visitor.convertToIrExpression(firDispatchReceiver) } diff --git a/compiler/testData/codegen/box/regressions/kt6485.kt b/compiler/testData/codegen/box/regressions/kt6485.kt index c0a03bb9875..26e99c5e6a0 100644 --- a/compiler/testData/codegen/box/regressions/kt6485.kt +++ b/compiler/testData/codegen/box/regressions/kt6485.kt @@ -1,4 +1,3 @@ -// IGNORE_BACKEND_FIR: JVM_IR // TARGET_BACKEND: JVM // WITH_RUNTIME diff --git a/compiler/testData/codegen/box/reified/anonymousObjectReifiedSupertype.kt b/compiler/testData/codegen/box/reified/anonymousObjectReifiedSupertype.kt index e74fb38c883..c8506afd518 100644 --- a/compiler/testData/codegen/box/reified/anonymousObjectReifiedSupertype.kt +++ b/compiler/testData/codegen/box/reified/anonymousObjectReifiedSupertype.kt @@ -1,4 +1,3 @@ -// IGNORE_BACKEND_FIR: JVM_IR // TARGET_BACKEND: JVM // WITH_RUNTIME diff --git a/compiler/testData/codegen/box/reified/approximateCapturedTypes.kt b/compiler/testData/codegen/box/reified/approximateCapturedTypes.kt index 0df0e8bd60b..97cae1cce6d 100644 --- a/compiler/testData/codegen/box/reified/approximateCapturedTypes.kt +++ b/compiler/testData/codegen/box/reified/approximateCapturedTypes.kt @@ -1,4 +1,3 @@ -// IGNORE_BACKEND_FIR: JVM_IR // TARGET_BACKEND: JVM // WITH_RUNTIME diff --git a/compiler/testData/codegen/box/reified/innerAnonymousObject.kt b/compiler/testData/codegen/box/reified/innerAnonymousObject.kt index 713d554e149..72ad5bc6347 100644 --- a/compiler/testData/codegen/box/reified/innerAnonymousObject.kt +++ b/compiler/testData/codegen/box/reified/innerAnonymousObject.kt @@ -1,4 +1,3 @@ -// IGNORE_BACKEND_FIR: JVM_IR // TARGET_BACKEND: JVM // WITH_RUNTIME diff --git a/compiler/testData/codegen/box/reified/nestedReifiedSignature.kt b/compiler/testData/codegen/box/reified/nestedReifiedSignature.kt index 3755f867ce3..3bbea827022 100644 --- a/compiler/testData/codegen/box/reified/nestedReifiedSignature.kt +++ b/compiler/testData/codegen/box/reified/nestedReifiedSignature.kt @@ -1,4 +1,3 @@ -// IGNORE_BACKEND_FIR: JVM_IR // TARGET_BACKEND: JVM // WITH_RUNTIME diff --git a/compiler/testData/codegen/box/reified/recursiveInnerAnonymousObject.kt b/compiler/testData/codegen/box/reified/recursiveInnerAnonymousObject.kt index f7e77001bc8..33ce0ad2d8a 100644 --- a/compiler/testData/codegen/box/reified/recursiveInnerAnonymousObject.kt +++ b/compiler/testData/codegen/box/reified/recursiveInnerAnonymousObject.kt @@ -1,4 +1,3 @@ -// IGNORE_BACKEND_FIR: JVM_IR // TARGET_BACKEND: JVM // WITH_RUNTIME diff --git a/compiler/testData/ir/irText/classes/delegatingConstructorCallToTypeAliasConstructor.fir.txt b/compiler/testData/ir/irText/classes/delegatingConstructorCallToTypeAliasConstructor.fir.txt index a84fdb5cc71..4fc7f46080d 100644 --- a/compiler/testData/ir/irText/classes/delegatingConstructorCallToTypeAliasConstructor.fir.txt +++ b/compiler/testData/ir/irText/classes/delegatingConstructorCallToTypeAliasConstructor.fir.txt @@ -39,7 +39,7 @@ FILE fqName: fileName:/delegatingConstructorCallToTypeAliasConstructor.kt CONSTRUCTOR visibility:public <> () returnType:.C1 [primary] BLOCK_BODY DELEGATING_CONSTRUCTOR_CALL 'public constructor (value: T of .Cell) [primary] declared in .Cell' - : + : kotlin.String value: CONST String type=kotlin.String value="O" INSTANCE_INITIALIZER_CALL classDescriptor='CLASS CLASS name:C1 modality:FINAL visibility:public superTypes:[.Cell]' PROPERTY FAKE_OVERRIDE name:value visibility:public modality:FINAL [fake_override,val] @@ -66,7 +66,6 @@ FILE fqName: fileName:/delegatingConstructorCallToTypeAliasConstructor.kt CONSTRUCTOR visibility:public <> () returnType:.C2 [primary] BLOCK_BODY DELEGATING_CONSTRUCTOR_CALL 'public constructor (value: T of .Cell) [primary] declared in .Cell' - : value: CONST String type=kotlin.String value="K" INSTANCE_INITIALIZER_CALL classDescriptor='CLASS CLASS name:C2 modality:FINAL visibility:public superTypes:[.Cell]' PROPERTY FAKE_OVERRIDE name:value visibility:public modality:FINAL [fake_override,val] diff --git a/compiler/testData/ir/irText/declarations/fakeOverrides.fir.txt b/compiler/testData/ir/irText/declarations/fakeOverrides.fir.txt index 610fc3efb39..ed0109fea13 100644 --- a/compiler/testData/ir/irText/declarations/fakeOverrides.fir.txt +++ b/compiler/testData/ir/irText/declarations/fakeOverrides.fir.txt @@ -65,7 +65,7 @@ FILE fqName: fileName:/fakeOverrides.kt CONSTRUCTOR visibility:public <> () returnType:.Test1 [primary] BLOCK_BODY DELEGATING_CONSTRUCTOR_CALL 'public constructor () [primary] declared in .CFoo' - : + : kotlin.String INSTANCE_INITIALIZER_CALL classDescriptor='CLASS CLASS name:Test1 modality:FINAL visibility:public superTypes:[.CFoo; .IFooStr; .IBar]' PROPERTY name:bar visibility:public modality:FINAL [val] FIELD PROPERTY_BACKING_FIELD name:bar type:kotlin.Int visibility:private [final] diff --git a/compiler/testData/ir/irText/declarations/parameters/constructor.fir.txt b/compiler/testData/ir/irText/declarations/parameters/constructor.fir.txt index 029b2533349..06985b9e57c 100644 --- a/compiler/testData/ir/irText/declarations/parameters/constructor.fir.txt +++ b/compiler/testData/ir/irText/declarations/parameters/constructor.fir.txt @@ -89,7 +89,7 @@ FILE fqName: fileName:/constructor.kt VALUE_PARAMETER name:i index:1 type:kotlin.Int BLOCK_BODY DELEGATING_CONSTRUCTOR_CALL 'public constructor (z: Z of .Test2.TestInner) [primary] declared in .Test2.TestInner' - : + : Z of .Test2.TestInner $this: GET_VAR ': .Test2 declared in .Test2' type=.Test2 origin=null z: GET_VAR 'z: Z of .Test2.TestInner declared in .Test2.TestInner.' type=Z of .Test2.TestInner origin=null FUN FAKE_OVERRIDE name:equals visibility:public modality:OPEN <> ($this:kotlin.Any, other:kotlin.Any?) returnType:kotlin.Boolean [fake_override,operator] @@ -189,7 +189,7 @@ FILE fqName: fileName:/constructor.kt CONST Int type=kotlin.Int value=42 BLOCK_BODY DELEGATING_CONSTRUCTOR_CALL 'public constructor (x: kotlin.Int) [primary] declared in .Test4' - : + : T of .Test4 x: CALL 'public final fun plus (other: kotlin.Int): kotlin.Int [operator] declared in kotlin.Int' type=kotlin.Int origin=PLUS $this: GET_VAR 'x: kotlin.Int declared in .Test4.' type=kotlin.Int origin=null other: GET_VAR 'y: kotlin.Int declared in .Test4.' type=kotlin.Int origin=null diff --git a/compiler/testData/ir/irText/declarations/parameters/typeParameterBoundedBySubclass.fir.txt b/compiler/testData/ir/irText/declarations/parameters/typeParameterBoundedBySubclass.fir.txt index 1aa9787fbf2..cf72949e9cd 100644 --- a/compiler/testData/ir/irText/declarations/parameters/typeParameterBoundedBySubclass.fir.txt +++ b/compiler/testData/ir/irText/declarations/parameters/typeParameterBoundedBySubclass.fir.txt @@ -24,7 +24,7 @@ FILE fqName: fileName:/typeParameterBoundedBySubclass.kt CONSTRUCTOR visibility:public <> () returnType:.Derived1 [primary] BLOCK_BODY DELEGATING_CONSTRUCTOR_CALL 'public constructor () [primary] declared in .Base1' - : + : .Derived1 INSTANCE_INITIALIZER_CALL classDescriptor='CLASS CLASS name:Derived1 modality:FINAL visibility:public superTypes:[.Base1<.Derived1>]' 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/thisOfGenericOuterClass.fir.txt b/compiler/testData/ir/irText/expressions/thisOfGenericOuterClass.fir.txt index 38b46607be0..52ee20f2a8b 100644 --- a/compiler/testData/ir/irText/expressions/thisOfGenericOuterClass.fir.txt +++ b/compiler/testData/ir/irText/expressions/thisOfGenericOuterClass.fir.txt @@ -73,6 +73,7 @@ FILE fqName: fileName:/thisOfGenericOuterClass.kt CONSTRUCTOR visibility:private <> () returnType:.test. [primary] BLOCK_BODY DELEGATING_CONSTRUCTOR_CALL 'public constructor (y: kotlin.Int) declared in .Outer.Inner' + <1>: kotlin.Int $this: GET_VAR ': .Outer declared in .test' type=.Outer origin=null y: CONST Int type=kotlin.Int value=42 INSTANCE_INITIALIZER_CALL classDescriptor='CLASS CLASS name: modality:FINAL visibility:local superTypes:[.Outer.Inner]' diff --git a/compiler/testData/ir/irText/stubs/genericClassInDifferentModule_m2.fir.txt b/compiler/testData/ir/irText/stubs/genericClassInDifferentModule_m2.fir.txt index f13a5225068..5313447e273 100644 --- a/compiler/testData/ir/irText/stubs/genericClassInDifferentModule_m2.fir.txt +++ b/compiler/testData/ir/irText/stubs/genericClassInDifferentModule_m2.fir.txt @@ -6,7 +6,7 @@ FILE fqName: fileName:/genericClassInDifferentModule_m2.kt VALUE_PARAMETER name:x index:0 type:T of .Derived1 BLOCK_BODY DELEGATING_CONSTRUCTOR_CALL 'public constructor (x: T of .Base) [primary] declared in .Base' - : + : T of .Derived1 x: GET_VAR 'x: T of .Derived1 declared in .Derived1.' type=T of .Derived1 origin=null INSTANCE_INITIALIZER_CALL classDescriptor='CLASS CLASS name:Derived1 modality:FINAL visibility:public superTypes:[.Base.Derived1>]' FUN name:foo visibility:public modality:FINAL ($this:.Derived1.Derived1>, y:Y of .Derived1.foo) returnType:T of .Derived1 diff --git a/compiler/testData/ir/irText/types/smartCastOnFakeOverrideReceiver.fir.txt b/compiler/testData/ir/irText/types/smartCastOnFakeOverrideReceiver.fir.txt index 9ec664b139b..7496bf918ee 100644 --- a/compiler/testData/ir/irText/types/smartCastOnFakeOverrideReceiver.fir.txt +++ b/compiler/testData/ir/irText/types/smartCastOnFakeOverrideReceiver.fir.txt @@ -176,7 +176,7 @@ FILE fqName: fileName:/smartCastOnFakeOverrideReceiver.kt CONSTRUCTOR visibility:public <> () returnType:.GB.GB, S of .GB> [primary] BLOCK_BODY DELEGATING_CONSTRUCTOR_CALL 'public constructor () [primary] declared in .GA' - : + : T of .GB INSTANCE_INITIALIZER_CALL classDescriptor='CLASS CLASS name:GB modality:FINAL visibility:public superTypes:[.GA.GB>]' FUN name:testGB1 visibility:public modality:FINAL <> ($this:.GB.GB, S of .GB>, a:kotlin.Any) returnType:kotlin.Unit $this: VALUE_PARAMETER name: type:.GB.GB, S of .GB>