Set correct IR origins for inc/dec operations
NB: in order to produce correct IR origins, the source element kinds for some FIR elements has been changed. As a side effect, mapping PSI to FIR slightly changed: namely, for `a[b]++`, `a[b]` used to be mapped on `set` call or callable reference, but now it is mapped on `get` call. ^KT-61891: Fixed ^KT-64387: Fixed
This commit is contained in:
committed by
Space Team
parent
8b1d87848d
commit
9aa8fb80e7
+1
-1
@@ -1,2 +1,2 @@
|
||||
Resolved to:
|
||||
0: (in test.B) operator fun set(i: kotlin.Int, a: test.B)
|
||||
0: (in test.B) operator fun get(i: kotlin.Int): test.B
|
||||
+3
-3
@@ -125,8 +125,6 @@ internal open class FirElementsRecorder : FirVisitor<Unit, MutableMap<KtElement,
|
||||
// For secondary constructors without explicit delegated constructor call, the PSI tree always create an empty
|
||||
// KtConstructorDelegationCall. In this case, the source in FIR has this fake source kind.
|
||||
it.kind == KtFakeSourceElementKind.ImplicitConstructor ||
|
||||
it.kind == KtFakeSourceElementKind.DesugaredPrefixNameReference ||
|
||||
it.kind == KtFakeSourceElementKind.DesugaredPostfixNameReference ||
|
||||
it.kind == KtFakeSourceElementKind.SmartCastExpression ||
|
||||
it.kind == KtFakeSourceElementKind.DanglingModifierList ||
|
||||
it.isSourceForArrayAugmentedAssign(element) ||
|
||||
@@ -147,7 +145,9 @@ internal open class FirElementsRecorder : FirVisitor<Unit, MutableMap<KtElement,
|
||||
private fun KtSourceElement.isSourceForCompoundAccess(fir: FirElement): Boolean {
|
||||
val psi = psi
|
||||
val parentPsi = psi?.parent
|
||||
if (kind != KtFakeSourceElementKind.DesugaredCompoundAssignment && kind != KtFakeSourceElementKind.DesugaredIncrementOrDecrement) return false
|
||||
if (kind != KtFakeSourceElementKind.DesugaredCompoundAssignment && kind !is KtFakeSourceElementKind.DesugaredIncrementOrDecrement) {
|
||||
return false
|
||||
}
|
||||
return when {
|
||||
psi is KtBinaryExpression || psi is KtUnaryExpression -> fir.isWriteInCompoundCall()
|
||||
parentPsi is KtBinaryExpression && psi == parentPsi.left -> fir.isReadInCompoundCall()
|
||||
|
||||
+1
-1
@@ -1,6 +1,6 @@
|
||||
KT element: KtPostfixExpression
|
||||
FIR element: FirFunctionCallImpl
|
||||
FIR source kind: DesugaredIncrementOrDecrement
|
||||
FIR source kind: DesugaredPostfixInc
|
||||
|
||||
FIR element rendered:
|
||||
R|<local>/<array>|.R|SubstitutionOverride</MyMap.set: R|kotlin/Unit|>|(R|<local>/<index_0>|, R|<local>/<unary>|.R|/A.inc|())
|
||||
|
||||
Vendored
+3
-3
@@ -1,9 +1,9 @@
|
||||
KT element: KtArrayAccessExpression
|
||||
FIR element: FirResolvedNamedReferenceImpl
|
||||
FIR source kind: KtRealSourceElementKind
|
||||
FIR element: FirFunctionCallImpl
|
||||
FIR source kind: DesugaredPostfixInc
|
||||
|
||||
FIR element rendered:
|
||||
R|SubstitutionOverride</MyMap.set: R|kotlin/Unit|>|
|
||||
R|<local>/<array>|.R|SubstitutionOverride</MyMap.get: R|A|>|(R|<local>/<index_0>|)
|
||||
|
||||
FIR FILE:
|
||||
FILE: [ResolvedTo(IMPORTS)] incWithArrayAccessConvention_set.kt
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
KT element: KtArrayAccessExpression
|
||||
FIR element: FirResolvedNamedReferenceImpl
|
||||
FIR source kind: KtRealSourceElementKind
|
||||
FIR element: FirFunctionCallImpl
|
||||
FIR source kind: DesugaredPostfixInc
|
||||
|
||||
FIR element rendered:
|
||||
R|test/B.set|
|
||||
R|<local>/<array>|.R|test/B.get|(R|<local>/<index_0>|)
|
||||
|
||||
FIR FILE:
|
||||
FILE: [ResolvedTo(IMPORTS)] setOperator.kt
|
||||
|
||||
+3
-3
@@ -1,9 +1,9 @@
|
||||
KT element: KtArrayAccessExpression
|
||||
FIR element: FirResolvedNamedReferenceImpl
|
||||
FIR source kind: KtRealSourceElementKind
|
||||
FIR element: FirFunctionCallImpl
|
||||
FIR source kind: DesugaredPostfixInc
|
||||
|
||||
FIR element rendered:
|
||||
R|test/B.set|
|
||||
R|<local>/<array>|.R|test/B.get|(R|<local>/<index_0>|)
|
||||
|
||||
FIR FILE:
|
||||
FILE: [ResolvedTo(IMPORTS)] setOperatorScript.kts
|
||||
|
||||
+1
-1
@@ -1,6 +1,6 @@
|
||||
KT element: KtPostfixExpression
|
||||
FIR element: FirVariableAssignmentImpl
|
||||
FIR source kind: DesugaredIncrementOrDecrement
|
||||
FIR source kind: DesugaredPostfixInc
|
||||
|
||||
FIR element rendered:
|
||||
R|<local>/nextUnnamedLibraryIndex| = R|<local>/<unary>|.R|kotlin/Int.inc|()
|
||||
|
||||
+1
-1
@@ -1,6 +1,6 @@
|
||||
KT element: KtPostfixExpression
|
||||
FIR element: FirVariableAssignmentImpl
|
||||
FIR source kind: DesugaredIncrementOrDecrement
|
||||
FIR source kind: DesugaredPostfixInc
|
||||
|
||||
FIR element rendered:
|
||||
R|<local>/nextUnnamedLibraryIndex| = R|<local>/<unary>|.R|kotlin/Int.inc|()
|
||||
|
||||
Reference in New Issue
Block a user