Fix codegen of do-while condition
The condition of a do-while loop can use variables declared in the loop (variables can only be declared inside a block). Previously this behaviour caused crash because after the block was generated, all variables declared inside that block were gone from myFrameMap #KT-3280 Fixed
This commit is contained in:
@@ -0,0 +1,15 @@
|
||||
fun box(): String {
|
||||
var x = 0
|
||||
do x++ while (x < 5)
|
||||
if (x != 5) return "Fail 1 $x"
|
||||
|
||||
var y = 0
|
||||
do { y++ } while (y < 5)
|
||||
if (y != 5) return "Fail 2 $y"
|
||||
|
||||
var z = ""
|
||||
do { z += z.length } while (z.length < 5)
|
||||
if (z != "01234") return "Fail 3 $z"
|
||||
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
fun box(): String {
|
||||
var fx = 1
|
||||
var fy = 1
|
||||
|
||||
do {
|
||||
var tmp = fy
|
||||
fy = fx + fy
|
||||
fx = tmp
|
||||
} while (fy < 100)
|
||||
|
||||
return if (fy == 144) "OK" else "Fail $fx $fy"
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
fun foo() {
|
||||
var x = 0
|
||||
do {
|
||||
x++
|
||||
var y = x + 5
|
||||
} while (y < 10)
|
||||
if (x != 5) throw AssertionError("$x")
|
||||
}
|
||||
|
||||
fun bar() {
|
||||
var b = false
|
||||
do {
|
||||
var x = "X"
|
||||
var y = "Y"
|
||||
b = true
|
||||
} while (x + y != "XY")
|
||||
if (!b) throw AssertionError()
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
foo()
|
||||
bar()
|
||||
return "OK"
|
||||
}
|
||||
Reference in New Issue
Block a user