[LL FIR] rebind returnTarget for delegate accessors during psi2fir
It is safe to rebind returnTarget to the original declaration during psi2fir as it doesn't affect the resolution. We already have the same logic for regular functions/property accessors. This change is crucial in the context of parallel implicit type resolution because it affects CFG builder in a bad way in the case of on-air resolution ^KT-56551
This commit is contained in:
committed by
Space Team
parent
c59ea8bd2a
commit
e0c931f69d
-9
@@ -292,15 +292,6 @@ private fun rebindReturnExpression(returnExpression: FirStatement, newTarget: Fi
|
||||
withFirEntry("expression", returnExpression)
|
||||
}
|
||||
|
||||
val target = returnExpression.target
|
||||
requireWithAttachment(target.labeledElement == oldTarget, { "Unexpected return target" }) {
|
||||
withFirSymbolEntry("newTarget", newTarget.propertySymbol)
|
||||
withFirSymbolEntry("oldTarget", oldTarget.propertySymbol)
|
||||
withFirEntry("target", target.labeledElement)
|
||||
}
|
||||
|
||||
target.bind(newTarget)
|
||||
|
||||
val functionCall = returnExpression.result
|
||||
rebindFunctionCall(functionCall, newTarget, oldTarget)
|
||||
}
|
||||
|
||||
+21
-3
@@ -11,7 +11,6 @@ import org.jetbrains.kotlin.analysis.low.level.api.fir.api.FirDesignation
|
||||
import org.jetbrains.kotlin.analysis.low.level.api.fir.project.structure.llFirModuleData
|
||||
import org.jetbrains.kotlin.analysis.low.level.api.fir.util.codeFragment
|
||||
import org.jetbrains.kotlin.analysis.low.level.api.fir.util.errorWithFirSpecificEntries
|
||||
import org.jetbrains.kotlin.utils.exceptions.errorWithAttachment
|
||||
import org.jetbrains.kotlin.analysis.utils.errors.requireIsInstance
|
||||
import org.jetbrains.kotlin.analysis.utils.errors.withPsiEntry
|
||||
import org.jetbrains.kotlin.fir.*
|
||||
@@ -32,6 +31,7 @@ import org.jetbrains.kotlin.name.NameUtils
|
||||
import org.jetbrains.kotlin.psi
|
||||
import org.jetbrains.kotlin.psi.*
|
||||
import org.jetbrains.kotlin.psi.psiUtil.hasExpectModifier
|
||||
import org.jetbrains.kotlin.utils.exceptions.errorWithAttachment
|
||||
|
||||
internal class RawFirNonLocalDeclarationBuilder private constructor(
|
||||
session: FirSession,
|
||||
@@ -103,8 +103,26 @@ internal class RawFirNonLocalDeclarationBuilder private constructor(
|
||||
}
|
||||
|
||||
override fun bindFunctionTarget(target: FirFunctionTarget, function: FirFunction) {
|
||||
val rewrittenTarget = functionsToRebind?.firstOrNull { it.realPsi == function.realPsi } ?: function
|
||||
super.bindFunctionTarget(target, rewrittenTarget)
|
||||
super.bindFunctionTarget(target, computeRebindTarget(function) ?: function)
|
||||
}
|
||||
|
||||
/**
|
||||
* @return [FirFunction] if another function should be used instead of [function] for [FirFunctionTarget]
|
||||
*
|
||||
* @see bindFunctionTarget
|
||||
* @see functionsToRebind
|
||||
*/
|
||||
private fun computeRebindTarget(function: FirFunction): FirFunction? {
|
||||
if (functionsToRebind.isNullOrEmpty()) return null
|
||||
val realPsi = function.realPsi
|
||||
if (realPsi != null) {
|
||||
return functionsToRebind.firstOrNull { it.realPsi == realPsi }
|
||||
}
|
||||
|
||||
val accessor = function as? FirPropertyAccessor ?: return null
|
||||
val accessorPsi = accessor.psi ?: return null
|
||||
|
||||
return functionsToRebind.firstOrNull { it is FirPropertyAccessor && it.isGetter == accessor.isGetter && it.psi == accessorPsi }
|
||||
}
|
||||
|
||||
override fun addCapturedTypeParameters(
|
||||
|
||||
Reference in New Issue
Block a user