[FIR] Preserve information about prefix/postfix-ness

This information is needed for dynamics
This commit is contained in:
Nikolay Lunyak
2022-03-31 17:54:25 +03:00
committed by teamcity
parent 93fa5ee696
commit 858999c1a1
3 changed files with 14 additions and 1 deletions
@@ -113,6 +113,8 @@ 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.isSourceForCompoundAccess(element)
}.psi as? KtElement
?: return
@@ -616,7 +616,12 @@ abstract class BaseFirBuilder<T>(val baseSession: FirSession, val context: Conte
val resultInitializer = buildFunctionCall {
source = desugaredSource
calleeReference = buildSimpleNamedReference {
source = operationReference?.toFirSourceElement()
val kind = if (prefix) {
KtFakeSourceElementKind.DesugaredPrefixNameReference
} else {
KtFakeSourceElementKind.DesugaredPostfixNameReference
}
source = operationReference?.toFirSourceElement(kind)
name = callName
}
explicitReceiver = if (prefix) {
@@ -110,6 +110,12 @@ sealed class KtFakeSourceElementKind : KtSourceElementKind() {
// x = x++ -> x = { val <unary> = x; x = <unary>.inc(); <unary> }
object DesugaredIncrementOrDecrement : KtFakeSourceElementKind()
// ++x --> `inc` calleeReference
object DesugaredPrefixNameReference : KtFakeSourceElementKind()
// x++ --> `inc` calleeReference
object DesugaredPostfixNameReference : KtFakeSourceElementKind()
// x !in list --> !(x in list) where ! and !(x in list) will have a fake source
object DesugaredInvertedContains : KtFakeSourceElementKind()