FIR: Do not run completion for lambda's explicit return too early

See the test case
Completion for synthetic call: x ?: return@myRun materialize()
makes `materialize()` while it's obviously too early for that
This commit is contained in:
Denis.Zharkov
2021-01-15 18:54:36 +03:00
parent 5afebb4e78
commit 9493e68584
8 changed files with 72 additions and 5 deletions
@@ -0,0 +1,15 @@
FILE: lambdasReturns.kt
public final fun <R> myRun(b: R|() -> R|): R|R| {
^myRun R|<local>/b|.R|SubstitutionOverride<kotlin/Function0.invoke: R|R|>|()
}
public final fun <T> materialize(): R|T| {
^materialize R|kotlin/TODO|()
}
public final fun foo(x: R|kotlin/String?|): R|kotlin/Unit| {
lval r: R|kotlin/Int| = R|/myRun|<R|kotlin/Int|>(<L> = myRun@fun <anonymous>(): R|kotlin/Int| {
lval y: R|kotlin/String| = R|<local>/x| ?: ^@myRun R?C|/materialize|()
^ R|<local>/y|.R|kotlin/String.length|
}
)
R|<local>/r|.R|kotlin/Int.minus|(Int(1))
}
@@ -0,0 +1,15 @@
// !DIAGNOSTICS: -UNUSED_VARIABLE
// !WITH_NEW_INFERENCE
fun <R> myRun(b: () -> R): R = b()
fun <T> materialize(): T = TODO()
fun foo(x: String?) {
val r = myRun {
val y = x ?: return@myRun materialize()
y.length
}
r.minus(1)
}