Support single-underscore variable names partially

Currently only parameters of lambdas/function expressions
and destructuring entries are allowed

 #KT-3824 In Progress
 #KT-2783 In Progress
This commit is contained in:
Denis Zharkov
2016-10-13 11:55:37 +03:00
parent 82364ad3e5
commit dbca310d8c
19 changed files with 319 additions and 21 deletions
@@ -6,9 +6,9 @@ fun useDeclaredVariables() {
}
fun checkersShouldRun() {
for ((@A a, <!UNDERSCORE_IS_RESERVED, UNUSED_VARIABLE!>_<!>)<!SYNTAX!><!>) {
for ((@A a, _)<!SYNTAX!><!>) {
}
}
annotation class A
annotation class A
@@ -5,7 +5,7 @@ fun useDeclaredVariables() {
}
fun checkersShouldRun() {
val (@A a, <!UNDERSCORE_IS_RESERVED, UNUSED_VARIABLE!>_<!>) = <!UNRESOLVED_REFERENCE!>unresolved<!>
val (@A a, _) = <!UNRESOLVED_REFERENCE!>unresolved<!>
}
annotation class A
annotation class A
@@ -5,7 +5,7 @@ fun useDeclaredVariables() {
}
fun checkersShouldRun() {
<!INITIALIZER_REQUIRED_FOR_DESTRUCTURING_DECLARATION!>val (@A a, <!UNDERSCORE_IS_RESERVED, UNUSED_VARIABLE!>_<!>)<!>
<!INITIALIZER_REQUIRED_FOR_DESTRUCTURING_DECLARATION!>val (@A a, _)<!>
}
annotation class A
annotation class A
@@ -0,0 +1,48 @@
class A {
operator fun component1() = 1
operator fun component2() = ""
}
class C {
operator fun iterator(): Iterator<A> = null!!
}
fun test() {
for ((x, _) in C()) {
foo(x, <!UNRESOLVED_REFERENCE!>_<!>)
}
for ((_, y) in C()) {
foo(<!UNRESOLVED_REFERENCE!>_<!>, y)
}
for ((_, _) in C()) {
foo(<!UNRESOLVED_REFERENCE!>_<!>, <!UNRESOLVED_REFERENCE!>_<!>)
}
for ((_ : Int, _ : String) in C()) {
foo(<!UNRESOLVED_REFERENCE!>_<!>, <!UNRESOLVED_REFERENCE!>_<!>)
}
for ((_ : String, _ : Int) in <!COMPONENT_FUNCTION_RETURN_TYPE_MISMATCH, COMPONENT_FUNCTION_RETURN_TYPE_MISMATCH!>C()<!>) {
foo(<!UNRESOLVED_REFERENCE!>_<!>, <!UNRESOLVED_REFERENCE!>_<!>)
}
val (x, _) = A()
val (_, y) = A()
foo(x, y)
foo(x, <!UNRESOLVED_REFERENCE!>_<!>)
foo(<!UNRESOLVED_REFERENCE!>_<!>, y)
val (<!REDECLARATION!>`_`<!>, z) = A()
foo(_, z)
val (_, <!NAME_SHADOWING, REDECLARATION!>`_`<!>) = A()
foo(<!TYPE_MISMATCH!>_<!>, y)
}
fun foo(<!UNUSED_PARAMETER!>x<!>: Int, <!UNUSED_PARAMETER!>y<!>: String) {}
@@ -0,0 +1,21 @@
package
public fun foo(/*0*/ x: kotlin.Int, /*1*/ y: kotlin.String): kotlin.Unit
public fun test(): kotlin.Unit
public final class A {
public constructor A()
public final operator fun component1(): kotlin.Int
public final operator fun component2(): kotlin.String
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
}
public final class C {
public constructor C()
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
public final operator fun iterator(): kotlin.collections.Iterator<A>
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
}