FIR: Use proper tower data contexts for postponed callable references

E.g., it should contain local scopes of containing lambdas
This commit is contained in:
Denis.Zharkov
2021-01-13 21:30:15 +03:00
parent ad30c6c380
commit 5f0d00a83f
6 changed files with 21 additions and 7 deletions
@@ -249,12 +249,18 @@ class FirCallResolver(
)
// No reset here!
val localCollector = CandidateCollector(components, components.resolutionStageRunner)
val result = towerResolver.runResolver(
info,
transformer.resolutionContext,
collector = localCollector,
manager = TowerResolveManager(localCollector),
)
val towerDataContext =
transformer.context.towerDataContextForCallableReferences[callableReferenceAccess] ?: transformer.context.towerDataContext
val result = transformer.context.withTowerDataContext(towerDataContext) {
towerResolver.runResolver(
info,
transformer.resolutionContext,
collector = localCollector,
manager = TowerResolveManager(localCollector),
)
}
val bestCandidates = result.bestCandidates()
val noSuccessfulCandidates = !result.currentApplicability.isSuccess
val reducedCandidates = if (noSuccessfulCandidates) {
@@ -74,6 +74,9 @@ class PostponedArgumentsAnalyzer(
val callableReferenceAccess = atom.reference
atom.analyzed = true
resolutionContext.bodyResolveContext.towerDataContextForCallableReferences.remove(callableReferenceAccess)
val (resultingCandidate, applicability) = atom.resultingCandidate
?: Pair(null, CandidateApplicability.INAPPLICABLE)
@@ -9,6 +9,7 @@ import kotlinx.collections.immutable.PersistentList
import kotlinx.collections.immutable.persistentListOf
import org.jetbrains.kotlin.fir.PrivateForInline
import org.jetbrains.kotlin.fir.declarations.*
import org.jetbrains.kotlin.fir.expressions.FirCallableReferenceAccess
import org.jetbrains.kotlin.fir.resolve.FirTowerDataContext
import org.jetbrains.kotlin.fir.resolve.FirTowerDataContextsForClassParts
import org.jetbrains.kotlin.fir.resolve.FirTowerDataElement
@@ -53,6 +54,7 @@ class BodyResolveContext(
var containers: PersistentList<FirDeclaration> = persistentListOf()
val towerDataContextForAnonymousFunctions: MutableMap<FirAnonymousFunctionSymbol, FirTowerDataContext> = mutableMapOf()
val towerDataContextForCallableReferences: MutableMap<FirCallableReferenceAccess, FirTowerDataContext> = mutableMapOf()
@set:PrivateForInline
var inferenceSession: FirInferenceSession = FirInferenceSession.DEFAULT
@@ -200,6 +202,7 @@ class BodyResolveContext(
): BodyResolveContext = BodyResolveContext(returnTypeCalculator, dataFlowAnalyzerContext, targetedLocalClasses, outerLocalClassForNested).apply {
file = this@BodyResolveContext.file
towerDataContextForAnonymousFunctions.putAll(this@BodyResolveContext.towerDataContextForAnonymousFunctions)
towerDataContextForCallableReferences.putAll(this@BodyResolveContext.towerDataContextForCallableReferences)
containers = this@BodyResolveContext.containers
towerDataContext = this@BodyResolveContext.towerDataContext
anonymousFunctionsAnalyzedInDependentContext.addAll(this@BodyResolveContext.anonymousFunctionsAnalyzedInDependentContext)
@@ -51,6 +51,7 @@ open class FirBodyResolveTransformer(
override fun transformFile(file: FirFile, data: ResolutionMode): CompositeTransformResult<FirFile> {
checkSessionConsistency(file)
context.cleanContextForAnonymousFunction()
context.towerDataContextForCallableReferences.clear()
context.cleanDataFlowContext()
@OptIn(PrivateForInline::class)
context.file = file
@@ -664,6 +664,8 @@ open class FirExpressionsResolveTransformer(transformer: FirBodyResolveTransform
return resolvedReference.compose()
}
context.towerDataContextForCallableReferences[callableReferenceAccess] = context.towerDataContext
dataFlowAnalyzer.exitCallableReference(callableReferenceAccessWithTransformedLHS)
return callableReferenceAccessWithTransformedLHS.compose()
}
@@ -1,4 +1,3 @@
// IGNORE_BACKEND_FIR: JVM_IR
// SKIP_JDK6
// TARGET_BACKEND: JVM
// WITH_RUNTIME