From 90c326950207e657fea3cd9ae5f6138abec4506a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Steven=20Sch=C3=A4fer?= Date: Fri, 10 May 2019 11:48:55 +0200 Subject: [PATCH] Fix type parameters in WrappedClassConstructorDescriptor IrConstructorCall gets type parameters from the class in addition to the constructor declaration. This behavior is already implemented for ClassConstructorDescriptorImpl, but was not implemented for WrappedClassConstructorDescriptor, leading to missing type arguments for calls to constructors generated in a lowering pass. --- .../backend/common/descriptors/WrappedDescriptors.kt | 9 ++++----- ...legatingConstructorCallToTypeAliasConstructor.fir.txt | 3 ++- .../ir/irText/declarations/fakeOverrides.fir.txt | 2 +- .../irText/declarations/parameters/constructor.fir.txt | 3 ++- .../parameters/typeParameterBoundedBySubclass.fir.txt | 2 +- .../stubs/genericClassInDifferentModule_m2.fir.txt | 2 +- 6 files changed, 11 insertions(+), 10 deletions(-) diff --git a/compiler/ir/backend.common/src/org/jetbrains/kotlin/backend/common/descriptors/WrappedDescriptors.kt b/compiler/ir/backend.common/src/org/jetbrains/kotlin/backend/common/descriptors/WrappedDescriptors.kt index c5e9985dea9..817697fce55 100644 --- a/compiler/ir/backend.common/src/org/jetbrains/kotlin/backend/common/descriptors/WrappedDescriptors.kt +++ b/compiler/ir/backend.common/src/org/jetbrains/kotlin/backend/common/descriptors/WrappedDescriptors.kt @@ -16,10 +16,7 @@ import org.jetbrains.kotlin.ir.descriptors.IrBasedDeclarationDescriptor import org.jetbrains.kotlin.ir.expressions.* import org.jetbrains.kotlin.ir.types.classifierOrFail import org.jetbrains.kotlin.ir.types.toKotlinType -import org.jetbrains.kotlin.ir.util.defaultType -import org.jetbrains.kotlin.ir.util.dump -import org.jetbrains.kotlin.ir.util.isAnnotationClass -import org.jetbrains.kotlin.ir.util.parentAsClass +import org.jetbrains.kotlin.ir.util.* import org.jetbrains.kotlin.name.Name import org.jetbrains.kotlin.resolve.constants.* import org.jetbrains.kotlin.resolve.descriptorUtil.classId @@ -445,7 +442,9 @@ open class WrappedClassConstructorDescriptor( (containingDeclaration.containingDeclaration as ClassDescriptor).thisAsReceiverParameter } - override fun getTypeParameters() = owner.typeParameters.map { it.descriptor } + override fun getTypeParameters() = + (owner.constructedClass.typeParameters + owner.typeParameters).map { it.descriptor } + override fun getValueParameters() = owner.valueParameters.asSequence() .mapNotNull { it.descriptor as? ValueParameterDescriptor } .toMutableList() diff --git a/compiler/testData/ir/irText/classes/delegatingConstructorCallToTypeAliasConstructor.fir.txt b/compiler/testData/ir/irText/classes/delegatingConstructorCallToTypeAliasConstructor.fir.txt index ee62aea17da..dd23bab978b 100644 --- a/compiler/testData/ir/irText/classes/delegatingConstructorCallToTypeAliasConstructor.fir.txt +++ b/compiler/testData/ir/irText/classes/delegatingConstructorCallToTypeAliasConstructor.fir.txt @@ -36,6 +36,7 @@ FILE fqName: fileName:/delegatingConstructorCallToTypeAliasConstructor.kt CONSTRUCTOR visibility:public <> () returnType:.C1 [primary] BLOCK_BODY DELEGATING_CONSTRUCTOR_CALL 'public constructor (value: T of ) [primary] declared in .Cell' + : value: CONST String type=kotlin.String value="O" INSTANCE_INITIALIZER_CALL classDescriptor='CLASS CLASS name:C1 modality:FINAL visibility:public superTypes:[.Cell]' FUN FAKE_OVERRIDE name:equals visibility:public modality:OPEN <> ($this:kotlin.Any, other:kotlin.Any?) returnType:kotlin.Boolean @@ -56,6 +57,7 @@ FILE fqName: fileName:/delegatingConstructorCallToTypeAliasConstructor.kt CONSTRUCTOR visibility:public <> () returnType:.C2 [primary] BLOCK_BODY DELEGATING_CONSTRUCTOR_CALL 'public constructor (value: T of ) [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]' FUN FAKE_OVERRIDE name:equals visibility:public modality:OPEN <> ($this:kotlin.Any, other:kotlin.Any?) returnType:kotlin.Boolean @@ -71,4 +73,3 @@ FILE fqName: fileName:/delegatingConstructorCallToTypeAliasConstructor.kt overridden: public open fun toString (): kotlin.String declared in kotlin.Any $this: VALUE_PARAMETER name: type:kotlin.Any - diff --git a/compiler/testData/ir/irText/declarations/fakeOverrides.fir.txt b/compiler/testData/ir/irText/declarations/fakeOverrides.fir.txt index a22170cde0b..11349a371e5 100644 --- a/compiler/testData/ir/irText/declarations/fakeOverrides.fir.txt +++ b/compiler/testData/ir/irText/declarations/fakeOverrides.fir.txt @@ -65,6 +65,7 @@ FILE fqName: fileName:/fakeOverrides.kt CONSTRUCTOR visibility:public <> () returnType:.Test1 [primary] BLOCK_BODY DELEGATING_CONSTRUCTOR_CALL 'public constructor () [primary] declared in .CFoo' + : 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:public [final] @@ -95,4 +96,3 @@ FILE fqName: fileName:/fakeOverrides.kt overridden: public open fun toString (): kotlin.String declared in kotlin.Any $this: VALUE_PARAMETER name: type:kotlin.Any - diff --git a/compiler/testData/ir/irText/declarations/parameters/constructor.fir.txt b/compiler/testData/ir/irText/declarations/parameters/constructor.fir.txt index 0e4fbec9091..7a8cb9475cd 100644 --- a/compiler/testData/ir/irText/declarations/parameters/constructor.fir.txt +++ b/compiler/testData/ir/irText/declarations/parameters/constructor.fir.txt @@ -87,6 +87,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 ) [primary] declared in .Test2.TestInner' + : z: GET_VAR 'z: Z of declared in .Test2.TestInner.' type=Z of origin=null FUN FAKE_OVERRIDE name:equals visibility:public modality:OPEN <> ($this:kotlin.Any, other:kotlin.Any?) returnType:kotlin.Boolean overridden: @@ -185,6 +186,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' + : x: CALL 'public final fun plus (other: kotlin.Int): kotlin.Int declared in kotlin.Int' type=kotlin.Int origin=null other: GET_VAR 'y: kotlin.Int declared in .Test4.' type=kotlin.Int origin=null FUN FAKE_OVERRIDE name:equals visibility:public modality:OPEN <> ($this:kotlin.Any, other:kotlin.Any?) returnType:kotlin.Boolean @@ -200,4 +202,3 @@ FILE fqName: fileName:/constructor.kt overridden: public open fun toString (): kotlin.String declared in kotlin.Any $this: VALUE_PARAMETER name: type:kotlin.Any - diff --git a/compiler/testData/ir/irText/declarations/parameters/typeParameterBoundedBySubclass.fir.txt b/compiler/testData/ir/irText/declarations/parameters/typeParameterBoundedBySubclass.fir.txt index 5476fb2dab0..4745b44131a 100644 --- a/compiler/testData/ir/irText/declarations/parameters/typeParameterBoundedBySubclass.fir.txt +++ b/compiler/testData/ir/irText/declarations/parameters/typeParameterBoundedBySubclass.fir.txt @@ -24,6 +24,7 @@ FILE fqName: fileName:/typeParameterBoundedBySubclass.kt CONSTRUCTOR visibility:public <> () returnType:.Derived1 [primary] BLOCK_BODY DELEGATING_CONSTRUCTOR_CALL 'public constructor () [primary] declared in .Base1' + : 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 overridden: @@ -86,4 +87,3 @@ FILE fqName: fileName:/typeParameterBoundedBySubclass.kt overridden: public open fun toString (): kotlin.String declared in kotlin.Any $this: VALUE_PARAMETER name: type:kotlin.Any - diff --git a/compiler/testData/ir/irText/stubs/genericClassInDifferentModule_m2.fir.txt b/compiler/testData/ir/irText/stubs/genericClassInDifferentModule_m2.fir.txt index f81c06981cf..3839b1e3f4b 100644 --- a/compiler/testData/ir/irText/stubs/genericClassInDifferentModule_m2.fir.txt +++ b/compiler/testData/ir/irText/stubs/genericClassInDifferentModule_m2.fir.txt @@ -6,6 +6,7 @@ FILE fqName: fileName:/genericClassInDifferentModule_m2.kt VALUE_PARAMETER name:x index:0 type:T of BLOCK_BODY DELEGATING_CONSTRUCTOR_CALL 'public constructor (x: T of ) [primary] declared in .Base' + : x: GET_VAR 'x: T of declared in .Derived1.' type=T of 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, y:Y of .Derived1.foo) returnType:T of .Derived1 @@ -59,4 +60,3 @@ FILE fqName: fileName:/genericClassInDifferentModule_m2.kt overridden: public open fun toString (): kotlin.String declared in kotlin.Any $this: VALUE_PARAMETER name: type:kotlin.Any -