FIR: Fix data-flow for jumps between members of local classes

First of all, note that currently ControlFlowGraphBuilder instance is fully mutable
and shared between all local classes and top-level classes in the same thread

Before this change, previous node for member of local class
was defined as lastNode

And in the case of implicit types, lastNode might be in a middle of another
local class member that is being resolved right now.

See the test:
- "a.length" expression in `bar` should be resolved because smart cast happens
before the class declaration
- "b.length" expression in `bar` should be unresolved because smart cast happens
in a different function

The latter case has been working incorrectly, the call was errorenously
resolved because "lastNode" were pointed just before "bar()" call in "foo"
This commit is contained in:
Denis Zharkov
2020-03-24 19:33:52 +03:00
parent 5584b206c0
commit 5539ad8ce8
7 changed files with 590 additions and 2 deletions
@@ -0,0 +1,46 @@
// !DUMP_CFG
inline fun <T> myRun(block: () -> T) = block()
fun test(a: Any, b: Any) {
if (a !is String) return
// (1)
class A {
fun foo() = myRun {
a.length
if (b is String) {
b.length
bar()
} else {
1
}
}
fun bar() = myRun {
b.<!UNRESOLVED_REFERENCE!>length<!>
a.length
baz()
}
fun baz() = 1
}
val x = object {
fun foo() = myRun {
a.length
if (b is String) {
b.length
bar()
} else {
1
}
}
fun bar() = myRun {
a.length
b.<!UNRESOLVED_REFERENCE!>length<!>
baz()
}
fun baz() = 1
}
}