FIR2IR: remove hacky & redundant resolve of delegating constructor calls
This commit is contained in:
@@ -405,30 +405,14 @@ class Fir2IrVisitor(
|
||||
}
|
||||
|
||||
private fun FirDelegatedConstructorCall.toIrDelegatingConstructorCall(): IrDelegatingConstructorCall? {
|
||||
val constructedClassSymbol = with(typeContext) {
|
||||
(constructedTypeRef as FirResolvedTypeRef).type.typeConstructor()
|
||||
} as? FirClassSymbol<*> ?: return null
|
||||
val constructedIrType = constructedTypeRef.toIrType(this@Fir2IrVisitor.session, declarationStorage)
|
||||
// TODO: find delegated constructor correctly
|
||||
val classId = constructedClassSymbol.classId
|
||||
var constructorSymbol: FirConstructorSymbol? = null
|
||||
constructedClassSymbol.buildUseSiteMemberScope(this@Fir2IrVisitor.session, ScopeSession())!!.processFunctionsByName(
|
||||
classId.shortClassName
|
||||
) {
|
||||
when {
|
||||
it !is FirConstructorSymbol -> {
|
||||
}
|
||||
arguments.size <= it.fir.valueParameters.size && constructorSymbol == null -> {
|
||||
constructorSymbol = it
|
||||
}
|
||||
}
|
||||
}
|
||||
val foundConstructorSymbol = constructorSymbol ?: return null
|
||||
val constructorSymbol = (this.calleeReference as? FirResolvedNamedReference)?.resolvedSymbol as? FirConstructorSymbol
|
||||
?: return null
|
||||
return convertWithOffsets { startOffset, endOffset ->
|
||||
IrDelegatingConstructorCallImpl(
|
||||
startOffset, endOffset,
|
||||
constructedIrType,
|
||||
declarationStorage.getIrFunctionSymbol(foundConstructorSymbol) as IrConstructorSymbol
|
||||
declarationStorage.getIrFunctionSymbol(constructorSymbol) as IrConstructorSymbol
|
||||
).apply {
|
||||
for ((index, argument) in arguments.withIndex()) {
|
||||
val argumentExpression = argument.toIrExpression()
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
// IGNORE_BACKEND_FIR: JVM_IR
|
||||
// TARGET_BACKEND: JVM
|
||||
// WITH_RUNTIME
|
||||
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
// IGNORE_BACKEND_FIR: JVM_IR
|
||||
// IGNORE_BACKEND: JS
|
||||
fun box(): String {
|
||||
val z = "K"
|
||||
|
||||
-1
@@ -1,4 +1,3 @@
|
||||
// IGNORE_BACKEND_FIR: JVM_IR
|
||||
open class A(val result: String) {
|
||||
constructor(x: Int, y: Int = 99) : this("$x$y")
|
||||
}
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
// IGNORE_BACKEND_FIR: JVM_IR
|
||||
open class A(val x: String, val z: String) {
|
||||
constructor(z: String) : this("O", z)
|
||||
}
|
||||
|
||||
@@ -14,7 +14,7 @@ FILE fqName:<root> fileName:/enumWithMultipleCtors.kt
|
||||
$this: VALUE_PARAMETER INSTANCE_RECEIVER name:<this> type:<root>.A.Y
|
||||
CONSTRUCTOR visibility:private <> () returnType:<uninitialized parent>.<anonymous> [primary]
|
||||
BLOCK_BODY
|
||||
DELEGATING_CONSTRUCTOR_CALL 'private constructor <init> (arg: kotlin.String) declared in <root>.A'
|
||||
DELEGATING_CONSTRUCTOR_CALL 'private constructor <init> () declared in <root>.A'
|
||||
INSTANCE_INITIALIZER_CALL classDescriptor='CLASS ENUM_ENTRY name:Y modality:FINAL visibility:private superTypes:[<root>.A]'
|
||||
FUN name:f visibility:public modality:FINAL <> ($this:<root>.A.Y) returnType:kotlin.String
|
||||
$this: VALUE_PARAMETER name:<this> type:<root>.A.Y
|
||||
@@ -29,8 +29,8 @@ FILE fqName:<root> fileName:/enumWithMultipleCtors.kt
|
||||
$this: VALUE_PARAMETER INSTANCE_RECEIVER name:<this> type:<root>.A.Z
|
||||
CONSTRUCTOR visibility:private <> () returnType:<uninitialized parent>.<anonymous> [primary]
|
||||
BLOCK_BODY
|
||||
DELEGATING_CONSTRUCTOR_CALL 'private constructor <init> (arg: kotlin.String) declared in <root>.A'
|
||||
arg: CONST Int type=kotlin.Int value=5
|
||||
DELEGATING_CONSTRUCTOR_CALL 'private constructor <init> (x: kotlin.Int) declared in <root>.A'
|
||||
x: CONST Int type=kotlin.Int value=5
|
||||
INSTANCE_INITIALIZER_CALL classDescriptor='CLASS ENUM_ENTRY name:Z modality:FINAL visibility:private superTypes:[<root>.A]'
|
||||
PROPERTY name:prop1 visibility:public modality:FINAL [val]
|
||||
FIELD PROPERTY_BACKING_FIELD name:prop1 type:kotlin.String visibility:private [final]
|
||||
|
||||
@@ -22,7 +22,7 @@ FILE fqName:<root> fileName:/enumWithSecondaryCtor.kt
|
||||
$this: VALUE_PARAMETER INSTANCE_RECEIVER name:<this> type:<root>.Test0.ZERO
|
||||
CONSTRUCTOR visibility:private <> () returnType:<uninitialized parent>.<anonymous> [primary]
|
||||
BLOCK_BODY
|
||||
DELEGATING_CONSTRUCTOR_CALL 'private constructor <init> (x: kotlin.Int) [primary] declared in <root>.Test0'
|
||||
DELEGATING_CONSTRUCTOR_CALL 'private constructor <init> () declared in <root>.Test0'
|
||||
INSTANCE_INITIALIZER_CALL classDescriptor='CLASS ENUM_ENTRY name:ZERO modality:FINAL visibility:private superTypes:[<root>.Test0]'
|
||||
CONSTRUCTOR visibility:private <> () returnType:<root>.Test0
|
||||
BLOCK_BODY
|
||||
@@ -92,7 +92,7 @@ FILE fqName:<root> fileName:/enumWithSecondaryCtor.kt
|
||||
$this: VALUE_PARAMETER INSTANCE_RECEIVER name:<this> type:<root>.Test1.ZERO
|
||||
CONSTRUCTOR visibility:private <> () returnType:<uninitialized parent>.<anonymous> [primary]
|
||||
BLOCK_BODY
|
||||
DELEGATING_CONSTRUCTOR_CALL 'private constructor <init> (x: kotlin.Int) [primary] declared in <root>.Test1'
|
||||
DELEGATING_CONSTRUCTOR_CALL 'private constructor <init> () declared in <root>.Test1'
|
||||
INSTANCE_INITIALIZER_CALL classDescriptor='CLASS ENUM_ENTRY name:ZERO modality:FINAL visibility:private superTypes:[<root>.Test1]'
|
||||
ENUM_ENTRY name:ONE
|
||||
class: CLASS ENUM_ENTRY name:ONE modality:FINAL visibility:private superTypes:[<root>.Test1]
|
||||
@@ -170,7 +170,7 @@ FILE fqName:<root> fileName:/enumWithSecondaryCtor.kt
|
||||
$this: VALUE_PARAMETER INSTANCE_RECEIVER name:<this> type:<root>.Test2.ZERO
|
||||
CONSTRUCTOR visibility:private <> () returnType:<uninitialized parent>.<anonymous> [primary]
|
||||
BLOCK_BODY
|
||||
DELEGATING_CONSTRUCTOR_CALL 'private constructor <init> (x: kotlin.Int) [primary] declared in <root>.Test2'
|
||||
DELEGATING_CONSTRUCTOR_CALL 'private constructor <init> () declared in <root>.Test2'
|
||||
INSTANCE_INITIALIZER_CALL classDescriptor='CLASS ENUM_ENTRY name:ZERO modality:FINAL visibility:private superTypes:[<root>.Test2]'
|
||||
FUN name:foo visibility:public modality:FINAL <> ($this:<root>.Test2.ZERO) returnType:kotlin.Unit
|
||||
$this: VALUE_PARAMETER name:<this> type:<root>.Test2.ZERO
|
||||
|
||||
+1
-1
@@ -60,7 +60,7 @@ FILE fqName:<root> fileName:/expectedSealedClass.kt
|
||||
$this: VALUE_PARAMETER INSTANCE_RECEIVER name:<this> type:<root>.Add
|
||||
CONSTRUCTOR visibility:public <> () returnType:<root>.Add [primary]
|
||||
BLOCK_BODY
|
||||
DELEGATING_CONSTRUCTOR_CALL 'private constructor <init> () [primary] declared in <root>.Ops'
|
||||
ERROR_CALL 'Cannot find delegated constructor call' type=<root>.Add
|
||||
INSTANCE_INITIALIZER_CALL classDescriptor='CLASS CLASS name:Add modality:FINAL visibility:public superTypes:[<root>.Ops]'
|
||||
FUN FAKE_OVERRIDE name:equals visibility:public modality:OPEN <> ($this:kotlin.Any, other:kotlin.Any?) returnType:kotlin.Boolean [fake_override,operator]
|
||||
overridden:
|
||||
|
||||
+1
-2
@@ -8,8 +8,7 @@ FILE fqName:<root> fileName:/thisReferenceBeforeClassDeclared.kt
|
||||
$this: VALUE_PARAMETER INSTANCE_RECEIVER name:<this> type:<root>.test.<no name provided>
|
||||
CONSTRUCTOR visibility:private <> () returnType:<root>.WithCompanion [primary]
|
||||
BLOCK_BODY
|
||||
DELEGATING_CONSTRUCTOR_CALL 'public constructor <init> (a: <root>.WithCompanion.Companion) [primary] declared in <root>.WithCompanion'
|
||||
a: GET_VAR '<this>: <uninitialized parent>.<anonymous> declared in <no parent>.<anonymous>' type=<uninitialized parent>.<anonymous> origin=null
|
||||
ERROR_CALL 'Cannot find delegated constructor call' type=<root>.WithCompanion
|
||||
INSTANCE_INITIALIZER_CALL classDescriptor='CLASS OBJECT name:<no name provided> modality:FINAL visibility:local superTypes:[<root>.WithCompanion]'
|
||||
CONSTRUCTOR_CALL 'private constructor <init> () [primary] declared in <root>.test.<no name provided>' type=<root>.test.<no name provided> origin=null
|
||||
VAR name:test2 type:<uninitialized parent>.<anonymous> [val]
|
||||
|
||||
Reference in New Issue
Block a user