FIR: copy builder inference session when creating snapshot for locals

This commit fixes one builder inference case from KT-49925
This commit is contained in:
Mikhail Glukhikh
2021-12-23 10:20:08 +03:00
committed by teamcity
parent 3f02309dad
commit f53cd22253
5 changed files with 11 additions and 7 deletions
@@ -23,6 +23,7 @@ import org.jetbrains.kotlin.fir.resolve.calls.InaccessibleImplicitReceiverValue
import org.jetbrains.kotlin.fir.resolve.calls.ResolutionContext
import org.jetbrains.kotlin.fir.resolve.dfa.DataFlowAnalyzerContext
import org.jetbrains.kotlin.fir.resolve.dfa.PersistentFlow
import org.jetbrains.kotlin.fir.resolve.inference.FirBuilderInferenceSession
import org.jetbrains.kotlin.fir.resolve.inference.FirCallCompleter
import org.jetbrains.kotlin.fir.resolve.inference.FirDelegatedPropertyInferenceSession
import org.jetbrains.kotlin.fir.resolve.inference.FirInferenceSession
@@ -348,6 +349,13 @@ class BodyResolveContext(
containingClass = this@BodyResolveContext.containingClass
replaceTowerDataContext(this@BodyResolveContext.towerDataContext)
anonymousFunctionsAnalyzedInDependentContext.addAll(this@BodyResolveContext.anonymousFunctionsAnalyzedInDependentContext)
// Looks like we should copy this session only for builder inference to be able
// to use information from local class inside it.
// However, we should not copy other kinds of inference sessions,
// otherwise we can "inherit" type variables from there provoking inference problems
if (this@BodyResolveContext.inferenceSession is FirBuilderInferenceSession) {
inferenceSession = this@BodyResolveContext.inferenceSession
}
}
// withElement PUBLIC API