IR: preserve argument evaluation order more carefully
1. receivers should be evaluated before named arguments;
2. just because an argument has no side effects doesn't mean it is not
affected by the other arguments' side effects - in that case it
should still be evaluated in source order.
#KT-47660 Fixed
This commit is contained in:
+13
-8
@@ -1,13 +1,18 @@
|
||||
|
||||
fun test(a: String, b: String): String {
|
||||
return a + b;
|
||||
class C(val x: String) {
|
||||
fun test(a: String, b: String): String =
|
||||
x + a + b
|
||||
}
|
||||
|
||||
fun String.test(a: String, b: String): String =
|
||||
this + a + b
|
||||
|
||||
fun box(): String {
|
||||
var res = "";
|
||||
val call = test(b = {res += "K"; "K"}(), a = {res+="O"; "O"}())
|
||||
|
||||
if (res != "KO" || call != "OK") return "fail: $res != KO or $call != OK"
|
||||
var res = ""
|
||||
var call = {res += "1"; "x"}().test(b = {res += "2"; "b"}(), a = {res += "3"; "a"}())
|
||||
if (res != "123" || call != "xab") return "fail1: $res != 123 or $call != xab"
|
||||
|
||||
res = ""
|
||||
call = {res += "1"; C("x")}().test(b = {res += "2"; "b"}(), a = {res += "3"; "a"}())
|
||||
if (res != "123" || call != "xab") return "fail2: $res != 123 or $call != xab"
|
||||
return "OK"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,8 @@
|
||||
fun box(): String {
|
||||
var x = "c"
|
||||
val call = test(c = x, b = { x = "a"; "b" }(), a = x)
|
||||
return if (call == "abc") "OK" else "fail: $call != abc"
|
||||
}
|
||||
|
||||
fun test(a: String, b: String, c: String): String =
|
||||
a + b + c
|
||||
Reference in New Issue
Block a user