JS: when recursive local function does not capture variables, give it name from top-level scope. See KT-15770
This commit is contained in:
committed by
Alexey Andreev
parent
70d2296e61
commit
ac0df8eef9
@@ -0,0 +1,43 @@
|
||||
var log = ""
|
||||
|
||||
fun foo() {
|
||||
fun local(x: String) {
|
||||
if (x.isEmpty()) return
|
||||
log += "foo(${x[0]});"
|
||||
local(x.substring(1))
|
||||
}
|
||||
local("OK")
|
||||
}
|
||||
|
||||
fun bar() {
|
||||
fun local(x: String) {
|
||||
if (x.isEmpty()) return
|
||||
log += "bar(${x[0]});"
|
||||
local(x.substring(1))
|
||||
}
|
||||
local("OK")
|
||||
}
|
||||
|
||||
fun baz(): Int {
|
||||
fun local(x: String) {
|
||||
if (x.isEmpty()) return
|
||||
log += "baz(${x[0]});"
|
||||
local(x.substring(1))
|
||||
}
|
||||
fun local(x: Int): Int = if (x == 0) 1 else x * local(x - 1)
|
||||
local("OK")
|
||||
return local(3)
|
||||
}
|
||||
|
||||
|
||||
fun box(): String {
|
||||
foo()
|
||||
bar()
|
||||
val result = baz()
|
||||
|
||||
if (result != 6) return "fail1: $result"
|
||||
|
||||
if (log != "foo(O);foo(K);bar(O);bar(K);baz(O);baz(K);") return "fail2: $result"
|
||||
|
||||
return "OK"
|
||||
}
|
||||
Reference in New Issue
Block a user