[FIR] Fix completion of FirDelegatedConstructorCall

Before this fix, changes that were made to the arguments list by calling
argumentList.transformArguments() were overriden by replaceArgumentList.
This fixes reverses the order in which these calls are made.
This also aligns the logic between the completion of qualified accesses
and delegated constructor calls.

#KT-59102 Fixed
This commit is contained in:
Kirill Rakhman
2023-06-12 12:01:15 +02:00
committed by Space Team
parent 267068546f
commit 4b85776405
14 changed files with 181 additions and 2 deletions
@@ -2738,6 +2738,12 @@ public class FirLightTreeJvmIrTextTestGenerated extends AbstractFirLightTreeJvmI
runTest("compiler/testData/ir/irText/firProblems/kt55458.kt");
}
@Test
@TestMetadata("kt59102.kt")
public void testKt59102() throws Exception {
runTest("compiler/testData/ir/irText/firProblems/kt59102.kt");
}
@Test
@TestMetadata("lambdaInEnumEntryConstructorCall.kt")
public void testLambdaInEnumEntryConstructorCall() throws Exception {
@@ -2738,6 +2738,12 @@ public class FirPsiJvmIrTextTestGenerated extends AbstractFirPsiJvmIrTextTest {
runTest("compiler/testData/ir/irText/firProblems/kt55458.kt");
}
@Test
@TestMetadata("kt59102.kt")
public void testKt59102() throws Exception {
runTest("compiler/testData/ir/irText/firProblems/kt59102.kt");
}
@Test
@TestMetadata("lambdaInEnumEntryConstructorCall.kt")
public void testLambdaInEnumEntryConstructorCall() throws Exception {
@@ -466,8 +466,6 @@ class FirCallCompletionResultsWriterTransformer(
delegatedConstructorCall.calleeReference as? FirNamedReferenceWithCandidate ?: return delegatedConstructorCall
val subCandidate = calleeReference.candidate
val argumentsMapping = runIf(!calleeReference.isError) { calleeReference.candidate.createArgumentsMapping() }
delegatedConstructorCall.argumentList.transformArguments(this, argumentsMapping)
if (calleeReference.isError) {
subCandidate.argumentMapping?.let {
delegatedConstructorCall.replaceArgumentList(buildArgumentListForErrorCall(delegatedConstructorCall.argumentList, it))
@@ -478,6 +476,10 @@ class FirCallCompletionResultsWriterTransformer(
delegatedConstructorCall.replaceArgumentList(buildResolvedArgumentList(it, delegatedConstructorCall.argumentList.source))
}
}
val argumentsMapping = runIf(!calleeReference.isError) { subCandidate.createArgumentsMapping() }
delegatedConstructorCall.argumentList.transformArguments(this, argumentsMapping)
return delegatedConstructorCall.apply {
replaceCalleeReference(calleeReference.toResolvedReference())
}
@@ -0,0 +1,36 @@
FILE fqName:<root> fileName:/kt59102.kt
CLASS CLASS name:XAlign modality:FINAL visibility:public superTypes:[kotlin.Any]
$this: VALUE_PARAMETER INSTANCE_RECEIVER name:<this> type:<root>.XAlign
CONSTRUCTOR visibility:public <> (bits:kotlin.Long) returnType:<root>.XAlign [primary]
VALUE_PARAMETER name:bits index:0 type:kotlin.Long
BLOCK_BODY
DELEGATING_CONSTRUCTOR_CALL 'public constructor <init> () declared in kotlin.Any'
INSTANCE_INITIALIZER_CALL classDescriptor='CLASS CLASS name:XAlign modality:FINAL visibility:public superTypes:[kotlin.Any]'
PROPERTY name:bits visibility:public modality:FINAL [val]
FIELD PROPERTY_BACKING_FIELD name:bits type:kotlin.Long visibility:private [final]
EXPRESSION_BODY
GET_VAR 'bits: kotlin.Long declared in <root>.XAlign.<init>' type=kotlin.Long origin=INITIALIZE_PROPERTY_FROM_PARAMETER
FUN DEFAULT_PROPERTY_ACCESSOR name:<get-bits> visibility:public modality:FINAL <> ($this:<root>.XAlign) returnType:kotlin.Long
correspondingProperty: PROPERTY name:bits visibility:public modality:FINAL [val]
$this: VALUE_PARAMETER name:<this> type:<root>.XAlign
BLOCK_BODY
RETURN type=kotlin.Nothing from='public final fun <get-bits> (): kotlin.Long declared in <root>.XAlign'
GET_FIELD 'FIELD PROPERTY_BACKING_FIELD name:bits type:kotlin.Long visibility:private [final]' type=kotlin.Long origin=null
receiver: GET_VAR '<this>: <root>.XAlign declared in <root>.XAlign.<get-bits>' type=<root>.XAlign origin=null
CONSTRUCTOR visibility:public <> () returnType:<root>.XAlign
BLOCK_BODY
DELEGATING_CONSTRUCTOR_CALL 'public constructor <init> (bits: kotlin.Long) declared in <root>.XAlign'
bits: CONST Long type=kotlin.Long value=2
FUN FAKE_OVERRIDE name:equals visibility:public modality:OPEN <> ($this:kotlin.Any, other:kotlin.Any?) returnType:kotlin.Boolean [fake_override,operator]
overridden:
public open fun equals (other: kotlin.Any?): kotlin.Boolean declared in kotlin.Any
$this: VALUE_PARAMETER name:<this> type:kotlin.Any
VALUE_PARAMETER name:other index:0 type:kotlin.Any?
FUN FAKE_OVERRIDE name:hashCode visibility:public modality:OPEN <> ($this:kotlin.Any) returnType:kotlin.Int [fake_override]
overridden:
public open fun hashCode (): kotlin.Int declared in kotlin.Any
$this: VALUE_PARAMETER name:<this> type:kotlin.Any
FUN FAKE_OVERRIDE name:toString visibility:public modality:OPEN <> ($this:kotlin.Any) returnType:kotlin.String [fake_override]
overridden:
public open fun toString (): kotlin.String declared in kotlin.Any
$this: VALUE_PARAMETER name:<this> type:kotlin.Any
@@ -0,0 +1,16 @@
class XAlign {
constructor(bits: Long) /* primary */ {
super/*Any*/()
/* <init>() */
}
val bits: Long
field = bits
get
constructor() {
this/*XAlign*/(bits = 2L)
}
}
+39
View File
@@ -0,0 +1,39 @@
FILE fqName:<root> fileName:/kt59102.kt
CLASS CLASS name:XAlign modality:FINAL visibility:public superTypes:[kotlin.Any]
$this: VALUE_PARAMETER INSTANCE_RECEIVER name:<this> type:<root>.XAlign
CONSTRUCTOR visibility:public <> (bits:kotlin.Long) returnType:<root>.XAlign [primary]
VALUE_PARAMETER name:bits index:0 type:kotlin.Long
BLOCK_BODY
DELEGATING_CONSTRUCTOR_CALL 'public constructor <init> () declared in kotlin.Any'
INSTANCE_INITIALIZER_CALL classDescriptor='CLASS CLASS name:XAlign modality:FINAL visibility:public superTypes:[kotlin.Any]'
PROPERTY name:bits visibility:public modality:FINAL [val]
FIELD PROPERTY_BACKING_FIELD name:bits type:kotlin.Long visibility:private [final]
EXPRESSION_BODY
GET_VAR 'bits: kotlin.Long declared in <root>.XAlign.<init>' type=kotlin.Long origin=INITIALIZE_PROPERTY_FROM_PARAMETER
FUN DEFAULT_PROPERTY_ACCESSOR name:<get-bits> visibility:public modality:FINAL <> ($this:<root>.XAlign) returnType:kotlin.Long
correspondingProperty: PROPERTY name:bits visibility:public modality:FINAL [val]
$this: VALUE_PARAMETER name:<this> type:<root>.XAlign
BLOCK_BODY
RETURN type=kotlin.Nothing from='public final fun <get-bits> (): kotlin.Long declared in <root>.XAlign'
GET_FIELD 'FIELD PROPERTY_BACKING_FIELD name:bits type:kotlin.Long visibility:private [final]' type=kotlin.Long origin=null
receiver: GET_VAR '<this>: <root>.XAlign declared in <root>.XAlign.<get-bits>' type=<root>.XAlign origin=null
CONSTRUCTOR visibility:public <> () returnType:<root>.XAlign
BLOCK_BODY
DELEGATING_CONSTRUCTOR_CALL 'public constructor <init> (bits: kotlin.Long) declared in <root>.XAlign'
bits: CALL 'public open fun toLong (): kotlin.Long declared in kotlin.Int' type=kotlin.Long origin=null
$this: CALL 'public final fun shl (bitCount: kotlin.Int): kotlin.Int declared in kotlin.Int' type=kotlin.Int origin=null
$this: CONST Int type=kotlin.Int value=1
bitCount: CONST Int type=kotlin.Int value=1
FUN FAKE_OVERRIDE name:equals visibility:public modality:OPEN <> ($this:kotlin.Any, other:kotlin.Any?) returnType:kotlin.Boolean [fake_override,operator]
overridden:
public open fun equals (other: kotlin.Any?): kotlin.Boolean declared in kotlin.Any
$this: VALUE_PARAMETER name:<this> type:kotlin.Any
VALUE_PARAMETER name:other index:0 type:kotlin.Any?
FUN FAKE_OVERRIDE name:hashCode visibility:public modality:OPEN <> ($this:kotlin.Any) returnType:kotlin.Int [fake_override]
overridden:
public open fun hashCode (): kotlin.Int declared in kotlin.Any
$this: VALUE_PARAMETER name:<this> type:kotlin.Any
FUN FAKE_OVERRIDE name:toString visibility:public modality:OPEN <> ($this:kotlin.Any) returnType:kotlin.String [fake_override]
overridden:
public open fun toString (): kotlin.String declared in kotlin.Any
$this: VALUE_PARAMETER name:<this> type:kotlin.Any
+3
View File
@@ -0,0 +1,3 @@
class XAlign(val bits: Long) {
constructor() : this(1 shl 1)
}
+16
View File
@@ -0,0 +1,16 @@
class XAlign {
constructor(bits: Long) /* primary */ {
super/*Any*/()
/* <init>() */
}
val bits: Long
field = bits
get
constructor() {
this/*XAlign*/(bits = 1.shl(bitCount = 1).toLong())
}
}
@@ -0,0 +1,26 @@
// CHECK:
// Mangled name: XAlign
// Public signature: /XAlign|null[0]
class XAlign {
// CHECK:
// Mangled name: XAlign{}bits
// Public signature: /XAlign.bits|-2314303284935245061[0]
val bits: Long
// CHECK JVM_IR:
// Mangled name: XAlign#<get-bits>(){}kotlin.Long
// Public signature: /XAlign.bits.<get-bits>|-8015099027032327963[0]
// CHECK JS_IR:
// Mangled name: XAlign#<get-bits>(){}
// Public signature: /XAlign.bits.<get-bits>|-3920031234897259044[0]
get
// CHECK:
// Mangled name: XAlign#<init>(){}
// Public signature: /XAlign.<init>|-5645683436151566731[0]
constructor()
// CHECK:
// Mangled name: XAlign#<init>(kotlin.Long){}
// Public signature: /XAlign.<init>|5217973964116651322[0]
constructor(bits: Long) /* primary */
}
@@ -2738,6 +2738,12 @@ public class ClassicJvmIrTextTestGenerated extends AbstractClassicJvmIrTextTest
runTest("compiler/testData/ir/irText/firProblems/kt55458.kt");
}
@Test
@TestMetadata("kt59102.kt")
public void testKt59102() throws Exception {
runTest("compiler/testData/ir/irText/firProblems/kt59102.kt");
}
@Test
@TestMetadata("lambdaInEnumEntryConstructorCall.kt")
public void testLambdaInEnumEntryConstructorCall() throws Exception {
@@ -2045,6 +2045,11 @@ public class KlibIrTextTestCaseGenerated extends AbstractKlibIrTextTestCase {
runTest("compiler/testData/ir/irText/firProblems/kt55458.kt");
}
@TestMetadata("kt59102.kt")
public void testKt59102() throws Exception {
runTest("compiler/testData/ir/irText/firProblems/kt59102.kt");
}
@TestMetadata("lambdaInEnumEntryConstructorCall.kt")
public void testLambdaInEnumEntryConstructorCall() throws Exception {
runTest("compiler/testData/ir/irText/firProblems/lambdaInEnumEntryConstructorCall.kt");
@@ -2348,6 +2348,12 @@ public class FirLightTreeJsIrTextTestGenerated extends AbstractFirLightTreeJsIrT
runTest("compiler/testData/ir/irText/firProblems/kt55458.kt");
}
@Test
@TestMetadata("kt59102.kt")
public void testKt59102() throws Exception {
runTest("compiler/testData/ir/irText/firProblems/kt59102.kt");
}
@Test
@TestMetadata("lambdaInEnumEntryConstructorCall.kt")
public void testLambdaInEnumEntryConstructorCall() throws Exception {
@@ -2348,6 +2348,12 @@ public class FirPsiJsIrTextTestGenerated extends AbstractFirPsiJsIrTextTest {
runTest("compiler/testData/ir/irText/firProblems/kt55458.kt");
}
@Test
@TestMetadata("kt59102.kt")
public void testKt59102() throws Exception {
runTest("compiler/testData/ir/irText/firProblems/kt59102.kt");
}
@Test
@TestMetadata("lambdaInEnumEntryConstructorCall.kt")
public void testLambdaInEnumEntryConstructorCall() throws Exception {
@@ -2348,6 +2348,12 @@ public class ClassicJsIrTextTestGenerated extends AbstractClassicJsIrTextTest {
runTest("compiler/testData/ir/irText/firProblems/kt55458.kt");
}
@Test
@TestMetadata("kt59102.kt")
public void testKt59102() throws Exception {
runTest("compiler/testData/ir/irText/firProblems/kt59102.kt");
}
@Test
@TestMetadata("lambdaInEnumEntryConstructorCall.kt")
public void testLambdaInEnumEntryConstructorCall() throws Exception {