Give unique names to fields for captured local functions

When a local function is captured, corresponding field accesses are
later transformed by the inliner. It doesn't have enough information to
restore the original semantics completely, so it has to rely on field
names. Local functions can be overloaded or can have names matching
local variable names, in both cases we generated fields with the same
name for captured values.

Now, we use the same '$<local-class-number>' suffix for field names for
local functions as it is present in the corresponding local class name.
This allows to distinguish captured local functions from captured local
variables and between different overloads of a function with the same
name.

 #KT-19827 Fixed
 #KT-18639 Fixed
This commit is contained in:
Dmitry Petrov
2017-10-11 14:07:34 +03:00
parent da99a100cc
commit 7a156e4407
12 changed files with 289 additions and 62 deletions
@@ -0,0 +1,19 @@
fun box(): String {
var s = ""
var foo = "O"
fun foo(x: String) {
s += x
}
fun foo() {
foo("K")
}
run {
foo(foo) // 1st foo is a local fun, second is a captured local var
foo()
}
return s
}