[FIR2IR] Fix generation of type arguments of delegated constructor calls

This commit is contained in:
Mikhail Glukhikh
2020-06-08 14:59:36 +03:00
parent 5c6f40b34a
commit 6f0eeecc64
14 changed files with 17 additions and 21 deletions
@@ -259,8 +259,8 @@ internal class ClassMemberGenerator(
val firDispatchReceiver = dispatchReceiver val firDispatchReceiver = dispatchReceiver
return convertWithOffsets { startOffset, endOffset -> return convertWithOffsets { startOffset, endOffset ->
val irConstructorSymbol = declarationStorage.getIrFunctionSymbol(constructorSymbol) as IrConstructorSymbol val irConstructorSymbol = declarationStorage.getIrFunctionSymbol(constructorSymbol) as IrConstructorSymbol
val typeArguments = (constructedTypeRef as? FirResolvedTypeRef)?.type?.typeArguments
if (constructorSymbol.fir.isFromEnumClass || constructorSymbol.fir.returnTypeRef.isEnum) { if (constructorSymbol.fir.isFromEnumClass || constructorSymbol.fir.returnTypeRef.isEnum) {
val typeArguments = (constructedTypeRef as? FirResolvedTypeRef)?.type?.typeArguments
IrEnumConstructorCallImpl( IrEnumConstructorCallImpl(
startOffset, endOffset, startOffset, endOffset,
constructedIrType, constructedIrType,
@@ -268,20 +268,22 @@ internal class ClassMemberGenerator(
typeArgumentsCount = typeArguments?.size ?: 0, typeArgumentsCount = typeArguments?.size ?: 0,
valueArgumentsCount = constructorSymbol.fir.valueParameters.size valueArgumentsCount = constructorSymbol.fir.valueParameters.size
).apply { ).apply {
if (typeArguments?.isNotEmpty() == true) {
val irType = (typeArguments.first() as ConeKotlinTypeProjection).type.toIrType()
putTypeArgument(0, irType)
}
} }
} else { } else {
IrDelegatingConstructorCallImpl( IrDelegatingConstructorCallImpl(
startOffset, endOffset, startOffset, endOffset,
constructedIrType, constructedIrType,
irConstructorSymbol, irConstructorSymbol,
valueArgumentsCount = irConstructorSymbol.owner.valueParameters.size, typeArgumentsCount = typeArguments?.size ?: 0,
typeArgumentsCount = irConstructorSymbol.owner.typeParameters.size valueArgumentsCount = irConstructorSymbol.owner.valueParameters.size
) )
}.let { }.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) { if (firDispatchReceiver !is FirNoReceiverExpression) {
it.dispatchReceiver = visitor.convertToIrExpression(firDispatchReceiver) it.dispatchReceiver = visitor.convertToIrExpression(firDispatchReceiver)
} }
-1
View File
@@ -1,4 +1,3 @@
// IGNORE_BACKEND_FIR: JVM_IR
// TARGET_BACKEND: JVM // TARGET_BACKEND: JVM
// WITH_RUNTIME // WITH_RUNTIME
@@ -1,4 +1,3 @@
// IGNORE_BACKEND_FIR: JVM_IR
// TARGET_BACKEND: JVM // TARGET_BACKEND: JVM
// WITH_RUNTIME // WITH_RUNTIME
@@ -1,4 +1,3 @@
// IGNORE_BACKEND_FIR: JVM_IR
// TARGET_BACKEND: JVM // TARGET_BACKEND: JVM
// WITH_RUNTIME // WITH_RUNTIME
@@ -1,4 +1,3 @@
// IGNORE_BACKEND_FIR: JVM_IR
// TARGET_BACKEND: JVM // TARGET_BACKEND: JVM
// WITH_RUNTIME // WITH_RUNTIME
@@ -1,4 +1,3 @@
// IGNORE_BACKEND_FIR: JVM_IR
// TARGET_BACKEND: JVM // TARGET_BACKEND: JVM
// WITH_RUNTIME // WITH_RUNTIME
@@ -1,4 +1,3 @@
// IGNORE_BACKEND_FIR: JVM_IR
// TARGET_BACKEND: JVM // TARGET_BACKEND: JVM
// WITH_RUNTIME // WITH_RUNTIME
@@ -39,7 +39,7 @@ FILE fqName:<root> fileName:/delegatingConstructorCallToTypeAliasConstructor.kt
CONSTRUCTOR visibility:public <> () returnType:<root>.C1 [primary] CONSTRUCTOR visibility:public <> () returnType:<root>.C1 [primary]
BLOCK_BODY BLOCK_BODY
DELEGATING_CONSTRUCTOR_CALL 'public constructor <init> (value: T of <root>.Cell) [primary] declared in <root>.Cell' DELEGATING_CONSTRUCTOR_CALL 'public constructor <init> (value: T of <root>.Cell) [primary] declared in <root>.Cell'
<T>: <none> <T>: kotlin.String
value: CONST String type=kotlin.String value="O" value: CONST String type=kotlin.String value="O"
INSTANCE_INITIALIZER_CALL classDescriptor='CLASS CLASS name:C1 modality:FINAL visibility:public superTypes:[<root>.Cell<kotlin.String>]' INSTANCE_INITIALIZER_CALL classDescriptor='CLASS CLASS name:C1 modality:FINAL visibility:public superTypes:[<root>.Cell<kotlin.String>]'
PROPERTY FAKE_OVERRIDE name:value visibility:public modality:FINAL [fake_override,val] PROPERTY FAKE_OVERRIDE name:value visibility:public modality:FINAL [fake_override,val]
@@ -66,7 +66,6 @@ FILE fqName:<root> fileName:/delegatingConstructorCallToTypeAliasConstructor.kt
CONSTRUCTOR visibility:public <> () returnType:<root>.C2 [primary] CONSTRUCTOR visibility:public <> () returnType:<root>.C2 [primary]
BLOCK_BODY BLOCK_BODY
DELEGATING_CONSTRUCTOR_CALL 'public constructor <init> (value: T of <root>.Cell) [primary] declared in <root>.Cell' DELEGATING_CONSTRUCTOR_CALL 'public constructor <init> (value: T of <root>.Cell) [primary] declared in <root>.Cell'
<T>: <none>
value: CONST String type=kotlin.String value="K" value: CONST String type=kotlin.String value="K"
INSTANCE_INITIALIZER_CALL classDescriptor='CLASS CLASS name:C2 modality:FINAL visibility:public superTypes:[<root>.Cell]' INSTANCE_INITIALIZER_CALL classDescriptor='CLASS CLASS name:C2 modality:FINAL visibility:public superTypes:[<root>.Cell]'
PROPERTY FAKE_OVERRIDE name:value visibility:public modality:FINAL [fake_override,val] PROPERTY FAKE_OVERRIDE name:value visibility:public modality:FINAL [fake_override,val]
@@ -65,7 +65,7 @@ FILE fqName:<root> fileName:/fakeOverrides.kt
CONSTRUCTOR visibility:public <> () returnType:<root>.Test1 [primary] CONSTRUCTOR visibility:public <> () returnType:<root>.Test1 [primary]
BLOCK_BODY BLOCK_BODY
DELEGATING_CONSTRUCTOR_CALL 'public constructor <init> () [primary] declared in <root>.CFoo' DELEGATING_CONSTRUCTOR_CALL 'public constructor <init> () [primary] declared in <root>.CFoo'
<T>: <none> <T>: kotlin.String
INSTANCE_INITIALIZER_CALL classDescriptor='CLASS CLASS name:Test1 modality:FINAL visibility:public superTypes:[<root>.CFoo<kotlin.String>; <root>.IFooStr; <root>.IBar]' INSTANCE_INITIALIZER_CALL classDescriptor='CLASS CLASS name:Test1 modality:FINAL visibility:public superTypes:[<root>.CFoo<kotlin.String>; <root>.IFooStr; <root>.IBar]'
PROPERTY name:bar visibility:public modality:FINAL [val] PROPERTY name:bar visibility:public modality:FINAL [val]
FIELD PROPERTY_BACKING_FIELD name:bar type:kotlin.Int visibility:private [final] FIELD PROPERTY_BACKING_FIELD name:bar type:kotlin.Int visibility:private [final]
@@ -89,7 +89,7 @@ FILE fqName:<root> fileName:/constructor.kt
VALUE_PARAMETER name:i index:1 type:kotlin.Int VALUE_PARAMETER name:i index:1 type:kotlin.Int
BLOCK_BODY BLOCK_BODY
DELEGATING_CONSTRUCTOR_CALL 'public constructor <init> (z: Z of <root>.Test2.TestInner) [primary] declared in <root>.Test2.TestInner' DELEGATING_CONSTRUCTOR_CALL 'public constructor <init> (z: Z of <root>.Test2.TestInner) [primary] declared in <root>.Test2.TestInner'
<Z>: <none> <Z>: Z of <root>.Test2.TestInner
$this: GET_VAR '<this>: <root>.Test2 declared in <root>.Test2' type=<root>.Test2 origin=null $this: GET_VAR '<this>: <root>.Test2 declared in <root>.Test2' type=<root>.Test2 origin=null
z: GET_VAR 'z: Z of <root>.Test2.TestInner declared in <root>.Test2.TestInner.<init>' type=Z of <root>.Test2.TestInner origin=null z: GET_VAR 'z: Z of <root>.Test2.TestInner declared in <root>.Test2.TestInner.<init>' type=Z of <root>.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] 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:<root> fileName:/constructor.kt
CONST Int type=kotlin.Int value=42 CONST Int type=kotlin.Int value=42
BLOCK_BODY BLOCK_BODY
DELEGATING_CONSTRUCTOR_CALL 'public constructor <init> (x: kotlin.Int) [primary] declared in <root>.Test4' DELEGATING_CONSTRUCTOR_CALL 'public constructor <init> (x: kotlin.Int) [primary] declared in <root>.Test4'
<T>: <none> <T>: T of <root>.Test4
x: CALL 'public final fun plus (other: kotlin.Int): kotlin.Int [operator] declared in kotlin.Int' type=kotlin.Int origin=PLUS 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 <root>.Test4.<init>' type=kotlin.Int origin=null $this: GET_VAR 'x: kotlin.Int declared in <root>.Test4.<init>' type=kotlin.Int origin=null
other: GET_VAR 'y: kotlin.Int declared in <root>.Test4.<init>' type=kotlin.Int origin=null other: GET_VAR 'y: kotlin.Int declared in <root>.Test4.<init>' type=kotlin.Int origin=null
@@ -24,7 +24,7 @@ FILE fqName:<root> fileName:/typeParameterBoundedBySubclass.kt
CONSTRUCTOR visibility:public <> () returnType:<root>.Derived1 [primary] CONSTRUCTOR visibility:public <> () returnType:<root>.Derived1 [primary]
BLOCK_BODY BLOCK_BODY
DELEGATING_CONSTRUCTOR_CALL 'public constructor <init> () [primary] declared in <root>.Base1' DELEGATING_CONSTRUCTOR_CALL 'public constructor <init> () [primary] declared in <root>.Base1'
<T>: <none> <T>: <root>.Derived1
INSTANCE_INITIALIZER_CALL classDescriptor='CLASS CLASS name:Derived1 modality:FINAL visibility:public superTypes:[<root>.Base1<<root>.Derived1>]' INSTANCE_INITIALIZER_CALL classDescriptor='CLASS CLASS name:Derived1 modality:FINAL visibility:public superTypes:[<root>.Base1<<root>.Derived1>]'
FUN FAKE_OVERRIDE name:equals visibility:public modality:OPEN <> ($this:kotlin.Any, other:kotlin.Any?) returnType:kotlin.Boolean [fake_override,operator] FUN FAKE_OVERRIDE name:equals visibility:public modality:OPEN <> ($this:kotlin.Any, other:kotlin.Any?) returnType:kotlin.Boolean [fake_override,operator]
overridden: overridden:
@@ -73,6 +73,7 @@ FILE fqName:<root> fileName:/thisOfGenericOuterClass.kt
CONSTRUCTOR visibility:private <> () returnType:<root>.test.<no name provided> [primary] CONSTRUCTOR visibility:private <> () returnType:<root>.test.<no name provided> [primary]
BLOCK_BODY BLOCK_BODY
DELEGATING_CONSTRUCTOR_CALL 'public constructor <init> (y: kotlin.Int) declared in <root>.Outer.Inner' DELEGATING_CONSTRUCTOR_CALL 'public constructor <init> (y: kotlin.Int) declared in <root>.Outer.Inner'
<1>: kotlin.Int
$this: GET_VAR '<this>: <root>.Outer<kotlin.Int> declared in <root>.test' type=<root>.Outer<kotlin.Int> origin=null $this: GET_VAR '<this>: <root>.Outer<kotlin.Int> declared in <root>.test' type=<root>.Outer<kotlin.Int> origin=null
y: CONST Int type=kotlin.Int value=42 y: CONST Int type=kotlin.Int value=42
INSTANCE_INITIALIZER_CALL classDescriptor='CLASS CLASS name:<no name provided> modality:FINAL visibility:local superTypes:[<root>.Outer.Inner<kotlin.Int>]' INSTANCE_INITIALIZER_CALL classDescriptor='CLASS CLASS name:<no name provided> modality:FINAL visibility:local superTypes:[<root>.Outer.Inner<kotlin.Int>]'
@@ -6,7 +6,7 @@ FILE fqName:<root> fileName:/genericClassInDifferentModule_m2.kt
VALUE_PARAMETER name:x index:0 type:T of <root>.Derived1 VALUE_PARAMETER name:x index:0 type:T of <root>.Derived1
BLOCK_BODY BLOCK_BODY
DELEGATING_CONSTRUCTOR_CALL 'public constructor <init> (x: T of <root>.Base) [primary] declared in <root>.Base' DELEGATING_CONSTRUCTOR_CALL 'public constructor <init> (x: T of <root>.Base) [primary] declared in <root>.Base'
<T>: <none> <T>: T of <root>.Derived1
x: GET_VAR 'x: T of <root>.Derived1 declared in <root>.Derived1.<init>' type=T of <root>.Derived1 origin=null x: GET_VAR 'x: T of <root>.Derived1 declared in <root>.Derived1.<init>' type=T of <root>.Derived1 origin=null
INSTANCE_INITIALIZER_CALL classDescriptor='CLASS CLASS name:Derived1 modality:FINAL visibility:public superTypes:[<root>.Base<T of <root>.Derived1>]' INSTANCE_INITIALIZER_CALL classDescriptor='CLASS CLASS name:Derived1 modality:FINAL visibility:public superTypes:[<root>.Base<T of <root>.Derived1>]'
FUN name:foo visibility:public modality:FINAL <Y> ($this:<root>.Derived1<T of <root>.Derived1>, y:Y of <root>.Derived1.foo) returnType:T of <root>.Derived1 FUN name:foo visibility:public modality:FINAL <Y> ($this:<root>.Derived1<T of <root>.Derived1>, y:Y of <root>.Derived1.foo) returnType:T of <root>.Derived1
@@ -176,7 +176,7 @@ FILE fqName:<root> fileName:/smartCastOnFakeOverrideReceiver.kt
CONSTRUCTOR visibility:public <> () returnType:<root>.GB<T of <root>.GB, S of <root>.GB> [primary] CONSTRUCTOR visibility:public <> () returnType:<root>.GB<T of <root>.GB, S of <root>.GB> [primary]
BLOCK_BODY BLOCK_BODY
DELEGATING_CONSTRUCTOR_CALL 'public constructor <init> () [primary] declared in <root>.GA' DELEGATING_CONSTRUCTOR_CALL 'public constructor <init> () [primary] declared in <root>.GA'
<T>: <none> <T>: T of <root>.GB
INSTANCE_INITIALIZER_CALL classDescriptor='CLASS CLASS name:GB modality:FINAL visibility:public superTypes:[<root>.GA<T of <root>.GB>]' INSTANCE_INITIALIZER_CALL classDescriptor='CLASS CLASS name:GB modality:FINAL visibility:public superTypes:[<root>.GA<T of <root>.GB>]'
FUN name:testGB1 visibility:public modality:FINAL <> ($this:<root>.GB<T of <root>.GB, S of <root>.GB>, a:kotlin.Any) returnType:kotlin.Unit FUN name:testGB1 visibility:public modality:FINAL <> ($this:<root>.GB<T of <root>.GB, S of <root>.GB>, a:kotlin.Any) returnType:kotlin.Unit
$this: VALUE_PARAMETER name:<this> type:<root>.GB<T of <root>.GB, S of <root>.GB> $this: VALUE_PARAMETER name:<this> type:<root>.GB<T of <root>.GB, S of <root>.GB>