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
@@ -19,8 +19,8 @@ FILE: buildSetWithVisitor.kt
public final fun R|Wrapper|.accept(visitor: R|AnyVisitor|): R|kotlin/Unit| {
R|<local>/visitor|.R|/AnyVisitor.visit|(this@R|/accept|)
}
public final fun bar(wrapper: R|Wrapper|): R|kotlin/collections/Set<ERROR CLASS: Cannot infer argument for type parameter E>| {
^bar <CS errors: kotlin/collections/buildSet>#<R|ERROR CLASS: Cannot infer argument for type parameter E|>(<L> = buildSet@fun R|kotlin/collections/MutableSet<ERROR CLASS: Cannot infer argument for type parameter E>|.<anonymous>(): R|kotlin/Unit| <inline=Inline, kind=EXACTLY_ONCE> {
public final fun bar(wrapper: R|Wrapper|): R|kotlin/collections/Set<kotlin/String>| {
^bar R|kotlin/collections/buildSet|<R|kotlin/String|>(<L> = buildSet@fun R|kotlin/collections/MutableSet<kotlin/String>|.<anonymous>(): R|kotlin/Unit| <inline=Inline, kind=EXACTLY_ONCE> {
R|<local>/wrapper|.R|/accept|(object : R|AnyVisitor| {
private constructor(): R|<anonymous>| {
super<R|AnyVisitor|>()
@@ -8,7 +8,7 @@ fun Wrapper.accept(visitor: AnyVisitor) {
visitor.visit(this)
}
fun bar(wrapper: Wrapper) = <!NEW_INFERENCE_NO_INFORMATION_FOR_PARAMETER!>buildSet<!> {
fun bar(wrapper: Wrapper) = buildSet {
wrapper.accept(object : AnyVisitor() {
override fun visit(arg: Wrapper) {
add(arg.tag)
@@ -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
@@ -1,6 +1,4 @@
// WITH_STDLIB
// IGNORE_BACKEND_FIR: JVM_IR
// FIR status: NEW_INFERENCE_NO_INFORMATION_FOR_PARAMETER on buildList calls (E)
@OptIn(ExperimentalStdlibApi::class)
fun foo1() {
buildList {
@@ -1,6 +1,4 @@
// DONT_TARGET_EXACT_BACKEND: WASM
// IGNORE_BACKEND_FIR: JVM_IR
// FIR status: NEW_INFERENCE_NO_INFORMATION_FOR_PARAMETER on buildList call (E)
// WITH_STDLIB
class TowerDataElementsForName() {