[FIR2IR] Handle delegating constructor call type arguments properly
This commit is contained in:
+12
-9
@@ -14,6 +14,7 @@ import org.jetbrains.kotlin.fir.expressions.FirDelegatedConstructorCall
|
|||||||
import org.jetbrains.kotlin.fir.expressions.FirExpression
|
import org.jetbrains.kotlin.fir.expressions.FirExpression
|
||||||
import org.jetbrains.kotlin.fir.expressions.impl.FirNoReceiverExpression
|
import org.jetbrains.kotlin.fir.expressions.impl.FirNoReceiverExpression
|
||||||
import org.jetbrains.kotlin.fir.references.FirResolvedNamedReference
|
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.symbols.impl.FirConstructorSymbol
|
||||||
import org.jetbrains.kotlin.fir.types.*
|
import org.jetbrains.kotlin.fir.types.*
|
||||||
import org.jetbrains.kotlin.ir.declarations.*
|
import org.jetbrains.kotlin.ir.declarations.*
|
||||||
@@ -256,30 +257,32 @@ 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
|
val typeArguments = (constructedTypeRef as? FirResolvedTypeRef)?.type?.fullyExpandedType(session)?.typeArguments
|
||||||
val constructor = constructorSymbol.fir
|
val constructor = constructorSymbol.fir
|
||||||
if (constructor.isFromEnumClass || constructor.returnTypeRef.isEnum) {
|
if (constructor.isFromEnumClass || constructor.returnTypeRef.isEnum) {
|
||||||
IrEnumConstructorCallImpl(
|
IrEnumConstructorCallImpl(
|
||||||
startOffset, endOffset,
|
startOffset, endOffset,
|
||||||
constructedIrType,
|
constructedIrType,
|
||||||
irConstructorSymbol,
|
irConstructorSymbol,
|
||||||
typeArgumentsCount = typeArguments?.size ?: 0,
|
typeArgumentsCount = constructor.typeParameters.size,
|
||||||
valueArgumentsCount = constructor.valueParameters.size
|
valueArgumentsCount = constructor.valueParameters.size
|
||||||
).apply {
|
)
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
IrDelegatingConstructorCallImpl(
|
IrDelegatingConstructorCallImpl(
|
||||||
startOffset, endOffset,
|
startOffset, endOffset,
|
||||||
constructedIrType,
|
constructedIrType,
|
||||||
irConstructorSymbol,
|
irConstructorSymbol,
|
||||||
typeArgumentsCount = typeArguments?.size ?: 0,
|
typeArgumentsCount = constructor.typeParameters.size,
|
||||||
valueArgumentsCount = irConstructorSymbol.owner.valueParameters.size
|
valueArgumentsCount = irConstructorSymbol.owner.valueParameters.size
|
||||||
)
|
)
|
||||||
}.let {
|
}.let {
|
||||||
if (typeArguments != null) {
|
if (constructor.typeParameters.isNotEmpty()) {
|
||||||
for ((index, typeArgument) in typeArguments.withIndex()) {
|
if (typeArguments?.isNotEmpty() == true) {
|
||||||
val irType = (typeArgument as ConeKotlinTypeProjection).type.toIrType()
|
for ((index, typeArgument) in typeArguments.withIndex()) {
|
||||||
it.putTypeArgument(index, irType)
|
if (index >= constructor.typeParameters.size) break
|
||||||
|
val irType = (typeArgument as ConeKotlinTypeProjection).type.toIrType()
|
||||||
|
it.putTypeArgument(index, irType)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (firDispatchReceiver !is FirNoReceiverExpression) {
|
if (firDispatchReceiver !is FirNoReceiverExpression) {
|
||||||
|
|||||||
Vendored
+1
@@ -66,6 +66,7 @@ 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>: kotlin.String
|
||||||
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]
|
||||||
|
|||||||
@@ -73,7 +73,6 @@ 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) [primary] declared in <root>.Outer.Inner'
|
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
|
$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>]'
|
||||||
|
|||||||
Reference in New Issue
Block a user