Support single-underscore named variables in JVM backend

There are mainly two kind of changes:
- skipping 'componentX' calls for destructuring entries named _
- fixing local variable table for them
 - skip entries for destructuring entries named _
 - use $noName_<i> format for lambda parameters named _

 #KT-3824 Fixed
 #KT-2783 Fixed
This commit is contained in:
Denis Zharkov
2016-10-20 17:23:42 +03:00
parent 544d8f5b66
commit a9fcee098d
18 changed files with 355 additions and 7 deletions
@@ -0,0 +1,3 @@
fun foo(block: (String, String, String) -> String): String = block("O", "fail", "K")
fun box() = foo { x, _, y -> x + y }
@@ -0,0 +1,9 @@
class A {
operator fun component1() = "O"
operator fun component2(): String = throw RuntimeException("fail 0")
operator fun component3() = "K"
}
fun foo(a: A, block: (A) -> String): String = block(a)
fun box() = foo(A()) { (x, _, y) -> x + y }
@@ -0,0 +1,3 @@
fun foo(block: (String, String, String) -> String): String = block("O", "fail", "K")
fun box() = foo(fun(x: String, _: String, y: String) = x + y)
@@ -0,0 +1,14 @@
class A {
operator fun component1() = 1
operator fun component2() = 2
}
fun box() : String {
val (_, b) = A()
val (a, _) = A()
val (`_`, c) = A()
return if (a == 1 && b == 2 && _ == 1 && c == 2) "OK" else "fail"
}
@@ -0,0 +1,43 @@
class Range(val from : C, val to: C) {
operator fun iterator() = It(from, to)
}
class It(val from: C, val to: C) {
var c = from.i
operator fun next(): C {
val next = C(c)
c++
return next
}
operator fun hasNext(): Boolean = c <= to.i
}
class C(val i : Int) {
operator fun component1() = i + 1
operator fun component2() = i + 2
operator fun rangeTo(c: C) = Range(this, c)
}
fun doTest(): String {
var s = ""
for ((a, _) in C(0)..C(2)) {
s += "$a;"
}
for ((_, b) in C(1)..C(3)) {
s += "$b;"
}
for ((_, `_`) in C(2)..C(4)) {
s += "$_;"
}
return s
}
fun box(): String {
val s = doTest()
return if (s == "1;2;3;3;4;5;4;5;6;") "OK" else "fail: $s"
}
@@ -0,0 +1,15 @@
class A {
operator fun component1() = "O"
operator fun component2(): String = throw RuntimeException("fail 0")
operator fun component3() = "K"
}
fun box(): String {
val aA = Array(1) { A() }
for ((x, _, z) in aA) {
return x + z
}
return "OK"
}