Supported inline of array convention simple cases; Fix for KT-9211: M13 an extension function that is inline, and for get(v) causes an exception when called using brackets

#KT-9211 Fixed
This commit is contained in:
Michael Bogdanov
2016-01-18 14:59:43 +03:00
parent 84dbdf2ccb
commit 23480a5698
17 changed files with 303 additions and 15 deletions
@@ -0,0 +1,15 @@
import test.*
fun box(): String {
val z = 1;
val p = z[2, 3]
if (p != 6) return "fail 1: $p"
z[2, 3] = p
if (res != 12) return "fail 2: $res"
return "OK"
}
@@ -0,0 +1,9 @@
package test
var res = 1
inline operator fun Int.get(z: Int, p: Int) = this + z + p
inline operator fun Int.set(z: Int, p: Int, l: Int) {
res = this + z + p + l
}
@@ -0,0 +1,17 @@
import test.*
fun box(): String {
with(A()) {
val z = 1;
val p = z[2, 3]
if (p != 6) return "fail 1: $p"
z[2, 3] = p
if (res != 12) return "fail 2: $res"
}
return "OK"
}
@@ -0,0 +1,13 @@
package test
var res = 1
class A {
inline operator fun Int.get(z: Int, p: Int) = this + z + p
inline operator fun Int.set(z: Int, p: Int, l: Int) {
res = this + z + p + l
}
}
@@ -0,0 +1,16 @@
import test.*
fun box(): String {
val z = 1;
val p = z[2, { 3 }]
if (p != 106) return "fail 1: $p"
val captured = 3;
z[2, { captured } ] = p
if (res != 112) return "fail 2: $res"
return "OK"
}
@@ -0,0 +1,9 @@
package test
var res = 1
inline operator fun Int.get(z: Int, p: () -> Int, defaultt: Int = 100) = this + z + p() + defaultt
inline operator fun Int.set(z: Int, p: () -> Int, l: Int/*, x : Int = 1000*/) {
res = this + z + p() + l /*+ x*/
}
@@ -0,0 +1,19 @@
import test.*
fun box(): String {
val z = 1;
with(A()) {
val p = z[2, { 3 }]
if (p != 106) return "fail 1: $p"
val captured = 3;
z[2, { captured }] = p
if (res != 112) return "fail 2: $res"
}
return "OK"
}
@@ -0,0 +1,12 @@
package test
var res = 1
class A {
inline operator fun Int.get(z: Int, p: () -> Int, defaultt: Int = 100) = this + z + p() + defaultt
inline operator fun Int.set(z: Int, p: () -> Int, l: Int/*, x : Int = 1000*/) {
res = this + z + p() + l /*+ x*/
}
}
@@ -0,0 +1,16 @@
import test.*
fun box(): String {
val z = 1;
val p = z[2, { 3 }]
if (p != 6) return "fail 1: $p"
val captured = 3;
z[2, { captured } ] = p
if (res != 12) return "fail 2: $res"
return "OK"
}
@@ -0,0 +1,9 @@
package test
var res = 1
inline operator fun Int.get(z: Int, p: () -> Int) = this + z + p()
inline operator fun Int.set(z: Int, p: () -> Int, l: Int) {
res = this + z + p() + l
}
@@ -0,0 +1,19 @@
import test.*
fun box(): String {
val z = 1;
with(A()) {
val p = z[2, { 3 }]
if (p != 6) return "fail 1: $p"
val captured = 3;
z[2, { captured }] = p
if (res != 12) return "fail 2: $res"
}
return "OK"
}
@@ -0,0 +1,13 @@
package test
var res = 1
class A {
inline operator fun Int.get(z: Int, p: () -> Int) = this + z + p()
inline operator fun Int.set(z: Int, p: () -> Int, l: Int) {
res = this + z + p() + l
}
}