[FIR2IR] Handle delegating constructor call type arguments properly

This commit is contained in:
Mikhail Glukhikh
2020-06-24 11:02:18 +03:00
parent 2cffbadbd5
commit bf009a4949
3 changed files with 13 additions and 10 deletions
@@ -14,6 +14,7 @@ import org.jetbrains.kotlin.fir.expressions.FirDelegatedConstructorCall
import org.jetbrains.kotlin.fir.expressions.FirExpression
import org.jetbrains.kotlin.fir.expressions.impl.FirNoReceiverExpression
import org.jetbrains.kotlin.fir.references.FirResolvedNamedReference
import org.jetbrains.kotlin.fir.resolve.fullyExpandedType
import org.jetbrains.kotlin.fir.symbols.impl.FirConstructorSymbol
import org.jetbrains.kotlin.fir.types.*
import org.jetbrains.kotlin.ir.declarations.*
@@ -256,30 +257,32 @@ internal class ClassMemberGenerator(
val firDispatchReceiver = dispatchReceiver
return convertWithOffsets { startOffset, endOffset ->
val irConstructorSymbol = declarationStorage.getIrFunctionSymbol(constructorSymbol) as IrConstructorSymbol
val typeArguments = (constructedTypeRef as? FirResolvedTypeRef)?.type?.typeArguments
val typeArguments = (constructedTypeRef as? FirResolvedTypeRef)?.type?.fullyExpandedType(session)?.typeArguments
val constructor = constructorSymbol.fir
if (constructor.isFromEnumClass || constructor.returnTypeRef.isEnum) {
IrEnumConstructorCallImpl(
startOffset, endOffset,
constructedIrType,
irConstructorSymbol,
typeArgumentsCount = typeArguments?.size ?: 0,
typeArgumentsCount = constructor.typeParameters.size,
valueArgumentsCount = constructor.valueParameters.size
).apply {
}
)
} else {
IrDelegatingConstructorCallImpl(
startOffset, endOffset,
constructedIrType,
irConstructorSymbol,
typeArgumentsCount = typeArguments?.size ?: 0,
typeArgumentsCount = constructor.typeParameters.size,
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 (constructor.typeParameters.isNotEmpty()) {
if (typeArguments?.isNotEmpty() == true) {
for ((index, typeArgument) in typeArguments.withIndex()) {
if (index >= constructor.typeParameters.size) break
val irType = (typeArgument as ConeKotlinTypeProjection).type.toIrType()
it.putTypeArgument(index, irType)
}
}
}
if (firDispatchReceiver !is FirNoReceiverExpression) {
@@ -66,6 +66,7 @@ FILE fqName:<root> fileName:/delegatingConstructorCallToTypeAliasConstructor.kt
CONSTRUCTOR visibility:public <> () returnType:<root>.C2 [primary]
BLOCK_BODY
DELEGATING_CONSTRUCTOR_CALL 'public constructor <init> (value: T of <root>.Cell) [primary] declared in <root>.Cell'
<T>: kotlin.String
value: CONST String type=kotlin.String value="K"
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]
@@ -73,7 +73,6 @@ FILE fqName:<root> fileName:/thisOfGenericOuterClass.kt
CONSTRUCTOR visibility:private <> () returnType:<root>.test.<no name provided> [primary]
BLOCK_BODY
DELEGATING_CONSTRUCTOR_CALL 'public constructor <init> (y: kotlin.Int) [primary] 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
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>]'