Make stack values for assignment-like operations lazy

As well as for other kinds of expressions

Within attached test they were generated twice in case of last expression of coroutine block,
because coroutine related codegen part is built upon assumption that all expressions should be generated lazily

Also add a test about unary postfix increment/decrement

 #KT-13156 Fixed
This commit is contained in:
Denis Zharkov
2016-07-25 11:50:35 +03:00
parent 0a8490a068
commit becb1f1f95
4 changed files with 128 additions and 17 deletions
@@ -0,0 +1,43 @@
class Controller {
var wasHandleResultCalled = false
suspend fun suspendHere(x: Continuation<String>) {
x.resume("OK")
}
operator fun handleResult(x: Unit, y: Continuation<Nothing>) {
wasHandleResultCalled = true
}
}
fun builder(coroutine c: Controller.() -> Continuation<Unit>) {
val controller = Controller()
c(controller).resume(Unit)
if (!controller.wasHandleResultCalled) throw java.lang.RuntimeException("fail 1")
}
fun box(): String {
var result = 0
builder {
result++
if (suspendHere() != "OK") throw java.lang.RuntimeException("fail 2")
result--
}
if (result != 0) return "fail 3"
builder {
--result
if (suspendHere() != "OK") throw java.lang.RuntimeException("fail 4")
++result
}
if (result != 0) return "fail 5"
return "OK"
}
@@ -0,0 +1,45 @@
class Controller {
var wasHandleResultCalled = false
suspend fun suspendHere(x: Continuation<String>) {
x.resume("OK")
}
operator fun handleResult(x: Unit, y: Continuation<Nothing>) {
wasHandleResultCalled = true
}
}
fun builder(coroutine c: Controller.() -> Continuation<Unit>) {
val controller = Controller()
c(controller).resume(Unit)
if (!controller.wasHandleResultCalled) throw java.lang.RuntimeException("fail 1")
}
var varWithCustomSetter: String = ""
set(value) {
if (field != "") throw java.lang.RuntimeException("fail 2")
field = value
}
fun box(): String {
var result = ""
builder {
result += "O"
if (suspendHere() != "OK") throw java.lang.RuntimeException("fail 3")
result += "K"
}
if (result != "OK") return "fail 4"
builder {
if (suspendHere() != "OK") throw java.lang.RuntimeException("fail 5")
varWithCustomSetter = "OK"
}
return varWithCustomSetter
}