KT-66411 [AA] Add fake source kind for single expression block around array assignments
A wrapper block was introduced as a part of fixing KT-59748, but was assigned a real source, which had `getOrBuildFir` confused because of the incorrectly built `KtToFirMapping` It is relevant for: - `if`, `when` expressions with an assignment as a single expression - Kotlin code fragments, when the assignment is being analysed as a single expression in the fragment ^KT-66411 Fixed
This commit is contained in:
committed by
Space Team
parent
ec06654a73
commit
b765cf3f99
-8
@@ -1,8 +0,0 @@
|
|||||||
<caret> resolved to:
|
|
||||||
0: (in kotlin.collections.MutableList) operator fun set(index: kotlin.Int, element: E): E
|
|
||||||
|
|
||||||
<caret_singleIfStatement> resolved to:
|
|
||||||
0: (in kotlin.collections.MutableList) operator fun set(index: kotlin.Int, element: E): E
|
|
||||||
|
|
||||||
<caret_singleWhenStatement> resolved to:
|
|
||||||
0: (in kotlin.collections.MutableList) operator fun set(index: kotlin.Int, element: E): E
|
|
||||||
@@ -2,7 +2,7 @@
|
|||||||
0: (in kotlin.collections.MutableList) operator fun set(index: kotlin.Int, element: E): E
|
0: (in kotlin.collections.MutableList) operator fun set(index: kotlin.Int, element: E): E
|
||||||
|
|
||||||
<caret_singleIfStatement> resolved to:
|
<caret_singleIfStatement> resolved to:
|
||||||
Nothing (Unresolved reference)
|
0: (in kotlin.collections.MutableList) operator fun set(index: kotlin.Int, element: E): E
|
||||||
|
|
||||||
<caret_singleWhenStatement> resolved to:
|
<caret_singleWhenStatement> resolved to:
|
||||||
Nothing (Unresolved reference)
|
0: (in kotlin.collections.MutableList) operator fun set(index: kotlin.Int, element: E): E
|
||||||
+1
-1
@@ -1,2 +1,2 @@
|
|||||||
Resolved to:
|
Resolved to:
|
||||||
Nothing (Unresolved reference)
|
0: (in MyList) operator fun set(index: kotlin.Int, value: kotlin.String)
|
||||||
+1
-1
@@ -1,2 +1,2 @@
|
|||||||
Resolved to:
|
Resolved to:
|
||||||
Nothing (Unresolved reference)
|
0: (in MyList) operator fun set(index: kotlin.Int, value: kotlin.String)
|
||||||
+2
-5
@@ -1,12 +1,9 @@
|
|||||||
KT element: KtBinaryExpression
|
KT element: KtBinaryExpression
|
||||||
FIR element: FirBlockImpl
|
FIR element: FirFunctionCallImpl
|
||||||
FIR source kind: KtRealSourceElementKind
|
FIR source kind: KtRealSourceElementKind
|
||||||
|
|
||||||
FIR element rendered:
|
FIR element rendered:
|
||||||
{
|
R|<local>/foo|.R|/Foo.set|(Int(10), String())
|
||||||
R|<local>/foo|.R|/Foo.set|(Int(10), String())
|
|
||||||
Unit
|
|
||||||
}
|
|
||||||
|
|
||||||
FIR FILE:
|
FIR FILE:
|
||||||
FILE: [ResolvedTo(IMPORTS)] arrayAssignOperatorAsSingleExpressionInIf.kt
|
FILE: [ResolvedTo(IMPORTS)] arrayAssignOperatorAsSingleExpressionInIf.kt
|
||||||
|
|||||||
+2
-5
@@ -1,12 +1,9 @@
|
|||||||
KT element: KtBinaryExpression
|
KT element: KtBinaryExpression
|
||||||
FIR element: FirBlockImpl
|
FIR element: FirFunctionCallImpl
|
||||||
FIR source kind: KtRealSourceElementKind
|
FIR source kind: KtRealSourceElementKind
|
||||||
|
|
||||||
FIR element rendered:
|
FIR element rendered:
|
||||||
{
|
R|<local>/foo|.R|/Foo.set|(Int(10), String())
|
||||||
R|<local>/foo|.R|/Foo.set|(Int(10), String())
|
|
||||||
Unit
|
|
||||||
}
|
|
||||||
|
|
||||||
FIR FILE:
|
FIR FILE:
|
||||||
FILE: [ResolvedTo(IMPORTS)] arrayAssignOperatorAsSingleExpressionInWhen.kt
|
FILE: [ResolvedTo(IMPORTS)] arrayAssignOperatorAsSingleExpressionInWhen.kt
|
||||||
|
|||||||
+3
-3
@@ -835,7 +835,7 @@ abstract class AbstractRawFirBuilder<T>(val baseSession: FirSession, val context
|
|||||||
if (operation == FirOperation.ASSIGN) {
|
if (operation == FirOperation.ASSIGN) {
|
||||||
val result = unwrappedLhs.convert()
|
val result = unwrappedLhs.convert()
|
||||||
result.replaceAnnotations(result.annotations.smartPlus(annotations))
|
result.replaceAnnotations(result.annotations.smartPlus(annotations))
|
||||||
source = result.source
|
source = result.source?.fakeElement(KtFakeSourceElementKind.IndexedAssignmentCoercionBlock)
|
||||||
statements += result.pullUpSafeCallIfNecessary()
|
statements += result.pullUpSafeCallIfNecessary()
|
||||||
} else {
|
} else {
|
||||||
val receiver = unwrappedLhs.convert()
|
val receiver = unwrappedLhs.convert()
|
||||||
@@ -846,13 +846,13 @@ abstract class AbstractRawFirBuilder<T>(val baseSession: FirSession, val context
|
|||||||
receiver.selector as FirExpression, baseSource, arrayAccessSource, operation, annotations, rhsAST, convert
|
receiver.selector as FirExpression, baseSource, arrayAccessSource, operation, annotations, rhsAST, convert
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
source = receiver.source
|
source = receiver.source?.fakeElement(KtFakeSourceElementKind.IndexedAssignmentCoercionBlock)
|
||||||
statements += receiver
|
statements += receiver
|
||||||
} else {
|
} else {
|
||||||
val augmentedArraySetCall = generateAugmentedArraySetCall(
|
val augmentedArraySetCall = generateAugmentedArraySetCall(
|
||||||
receiver, baseSource, arrayAccessSource, operation, annotations, rhsAST, convert
|
receiver, baseSource, arrayAccessSource, operation, annotations, rhsAST, convert
|
||||||
)
|
)
|
||||||
source = augmentedArraySetCall.source
|
source = augmentedArraySetCall.source?.fakeElement(KtFakeSourceElementKind.IndexedAssignmentCoercionBlock)
|
||||||
statements += augmentedArraySetCall
|
statements += augmentedArraySetCall
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -144,6 +144,10 @@ sealed class KtFakeSourceElementKind(final override val shouldSkipErrorTypeRepor
|
|||||||
// with a fake sources for the block which refers to the wrapped expression
|
// with a fake sources for the block which refers to the wrapped expression
|
||||||
object SingleExpressionBlock : KtFakeSourceElementKind()
|
object SingleExpressionBlock : KtFakeSourceElementKind()
|
||||||
|
|
||||||
|
// this source is used for a single fake block created for indexed assignments expression,
|
||||||
|
// see ImplicitUnit.IndexedAssignmentCoercion
|
||||||
|
object IndexedAssignmentCoercionBlock : KtFakeSourceElementKind()
|
||||||
|
|
||||||
// Contract statements are wrapped in a special block to be reused between a contract FIR and a function body.
|
// Contract statements are wrapped in a special block to be reused between a contract FIR and a function body.
|
||||||
object ContractBlock : KtFakeSourceElementKind()
|
object ContractBlock : KtFakeSourceElementKind()
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user