UNUSED_VARIABLE is now reported only for last entry of destructuring declaration (if applicable) #KT-14221 Fixed

This commit is contained in:
Mikhail Glukhikh
2016-10-07 20:38:00 +03:00
parent 126304c197
commit 8d48b0d2a0
24 changed files with 65 additions and 31 deletions
@@ -0,0 +1,9 @@
data class D(val x: Int, val y: Int, val z: Int)
fun foo(): Int {
val (x, y, z) = D(1, 2, 3)
return y + z // x is not used, but we cannot do anything with it
}
fun bar(): Int {
val (x, y, <!UNUSED_VARIABLE!>z<!>) = D(1, 2, 3)
return y + x // z is not used
}
@@ -0,0 +1,18 @@
package
public fun bar(): kotlin.Int
public fun foo(): kotlin.Int
public final data class D {
public constructor D(/*0*/ x: kotlin.Int, /*1*/ y: kotlin.Int, /*2*/ z: kotlin.Int)
public final val x: kotlin.Int
public final val y: kotlin.Int
public final val z: kotlin.Int
public final operator /*synthesized*/ fun component1(): kotlin.Int
public final operator /*synthesized*/ fun component2(): kotlin.Int
public final operator /*synthesized*/ fun component3(): kotlin.Int
public final /*synthesized*/ fun copy(/*0*/ x: kotlin.Int = ..., /*1*/ y: kotlin.Int = ..., /*2*/ z: kotlin.Int = ...): D
public open override /*1*/ /*synthesized*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
public open override /*1*/ /*synthesized*/ fun hashCode(): kotlin.Int
public open override /*1*/ /*synthesized*/ fun toString(): kotlin.String
}
@@ -8,7 +8,7 @@ fun foo() {
for (@Ann(1) i in 1..100) {}
for (@Ann(2) i in 1..100) {}
for (<!WRONG_ANNOTATION_TARGET!>@Ann(3)<!> (x, @Ann(4) y) in bar()) {}
for (<!WRONG_ANNOTATION_TARGET!>@Ann(3)<!> (x, @Ann(4) <!UNUSED_VARIABLE!>y<!>) in bar()) {}
for (@<!UNRESOLVED_REFERENCE!>Err<!>() (x,y) in bar()) {}
for (@<!UNRESOLVED_REFERENCE!>Err<!>() (x,<!UNUSED_VARIABLE!>y<!>) in bar()) {}
}
@@ -22,11 +22,11 @@ fun f() {
}
for (<!VAL_OR_VAR_ON_LOOP_PARAMETER!>val<!> (i,j) in Coll()) {
for (<!VAL_OR_VAR_ON_LOOP_PARAMETER!>val<!> (i,<!UNUSED_VARIABLE!>j<!>) in Coll()) {
}
for (<!VAL_OR_VAR_ON_LOOP_PARAMETER!>var<!> (i,j) in Coll()) {
for (<!VAL_OR_VAR_ON_LOOP_PARAMETER!>var<!> (i,<!UNUSED_VARIABLE!>j<!>) in Coll()) {
}
}
@@ -4,5 +4,5 @@ class A {
}
fun a(aa : A) {
val (<!UNUSED_VARIABLE!>a<!>: String, <!UNUSED_VARIABLE!>b1<!>: String) = <!COMPONENT_FUNCTION_RETURN_TYPE_MISMATCH, COMPONENT_FUNCTION_RETURN_TYPE_MISMATCH!>aa<!>
val (a: String, <!UNUSED_VARIABLE!>b1<!>: String) = <!COMPONENT_FUNCTION_RETURN_TYPE_MISMATCH, COMPONENT_FUNCTION_RETURN_TYPE_MISMATCH!>aa<!>
}
@@ -5,10 +5,10 @@ class A {
fun a(aa : A?, b : Any) {
if (aa != null) {
val (<!UNUSED_VARIABLE!>a1<!>, <!UNUSED_VARIABLE!>b1<!>) = <!DEBUG_INFO_SMARTCAST!>aa<!>;
val (a1, <!UNUSED_VARIABLE!>b1<!>) = <!DEBUG_INFO_SMARTCAST!>aa<!>;
}
if (b is A) {
val (<!UNUSED_VARIABLE!>a1<!>, <!UNUSED_VARIABLE!>b1<!>) = <!DEBUG_INFO_SMARTCAST!>b<!>;
val (a1, <!UNUSED_VARIABLE!>b1<!>) = <!DEBUG_INFO_SMARTCAST!>b<!>;
}
}
@@ -4,11 +4,11 @@ class A {
}
fun a() {
val (<!REDECLARATION, UNUSED_VARIABLE!>a<!>, <!NAME_SHADOWING, REDECLARATION, UNUSED_VARIABLE!>a<!>) = A()
val (<!UNUSED_VARIABLE!>x<!>, <!REDECLARATION, UNUSED_VARIABLE!>y<!>) = A();
val (<!REDECLARATION!>a<!>, <!NAME_SHADOWING, REDECLARATION, UNUSED_VARIABLE!>a<!>) = A()
val (x, <!REDECLARATION, UNUSED_VARIABLE!>y<!>) = A();
val <!REDECLARATION!>b<!> = 1
use(b)
val (<!NAME_SHADOWING, REDECLARATION, UNUSED_VARIABLE!>b<!>, <!NAME_SHADOWING, REDECLARATION, UNUSED_VARIABLE!>y<!>) = A();
val (<!NAME_SHADOWING, REDECLARATION!>b<!>, <!NAME_SHADOWING, REDECLARATION, UNUSED_VARIABLE!>y<!>) = A();
}
@@ -8,7 +8,7 @@ class C {
}
fun test() {
for ((x, y) in C()) {
for ((x, <!UNUSED_VARIABLE!>y<!>) in C()) {
}
}
@@ -8,7 +8,7 @@ class C {
}
fun test() {
for ((x: Double, y: Int) in <!COMPONENT_FUNCTION_RETURN_TYPE_MISMATCH, COMPONENT_FUNCTION_RETURN_TYPE_MISMATCH!>C()<!>) {
for ((x: Double, <!UNUSED_VARIABLE!>y<!>: Int) in <!COMPONENT_FUNCTION_RETURN_TYPE_MISMATCH, COMPONENT_FUNCTION_RETURN_TYPE_MISMATCH!>C()<!>) {
}
}
@@ -9,7 +9,7 @@ class C {
}
fun test() {
for ((x, y) in <!COMPONENT_FUNCTION_AMBIGUITY!>C()<!>) {
for ((x, <!UNUSED_VARIABLE!>y<!>) in <!COMPONENT_FUNCTION_AMBIGUITY!>C()<!>) {
}
}
@@ -7,7 +7,7 @@ class C {
}
fun test() {
for ((x, y) in <!COMPONENT_FUNCTION_MISSING!>C()<!>) {
for ((x, <!UNUSED_VARIABLE!>y<!>) in <!COMPONENT_FUNCTION_MISSING!>C()<!>) {
}
}
@@ -6,7 +6,7 @@ fun useDeclaredVariables() {
}
fun checkersShouldRun() {
for ((@A a, <!UNDERSCORE_IS_RESERVED!>_<!>)<!SYNTAX!><!>) {
for ((@A a, <!UNDERSCORE_IS_RESERVED, UNUSED_VARIABLE!>_<!>)<!SYNTAX!><!>) {
}
}
@@ -8,7 +8,7 @@ class C {
}
fun test() {
for ((x, y) in C()) {
for ((x, <!UNUSED_VARIABLE!>y<!>) in C()) {
}
}
@@ -8,7 +8,7 @@ class C {
}
fun test() {
for ((x: Int, y: Double) in C()) {
for ((x: Int, <!UNUSED_VARIABLE!>y<!>: Double) in C()) {
}
}
@@ -8,7 +8,7 @@ class C {
}
fun test() {
for ((<!REDECLARATION!>x<!>, <!NAME_SHADOWING, REDECLARATION!>x<!>) in C()) {
for ((<!REDECLARATION!>x<!>, <!NAME_SHADOWING, REDECLARATION, UNUSED_VARIABLE!>x<!>) in C()) {
}
}
@@ -5,7 +5,7 @@ fun useDeclaredVariables() {
}
fun checkersShouldRun() {
val (@A <!UNUSED_VARIABLE!>a<!>, <!UNDERSCORE_IS_RESERVED, UNUSED_VARIABLE!>_<!>) = <!UNRESOLVED_REFERENCE!>unresolved<!>
val (@A a, <!UNDERSCORE_IS_RESERVED, UNUSED_VARIABLE!>_<!>) = <!UNRESOLVED_REFERENCE!>unresolved<!>
}
annotation class A
@@ -5,7 +5,7 @@ fun useDeclaredVariables() {
}
fun checkersShouldRun() {
<!INITIALIZER_REQUIRED_FOR_DESTRUCTURING_DECLARATION!>val (@A <!UNUSED_VARIABLE!>a<!>, <!UNDERSCORE_IS_RESERVED, UNUSED_VARIABLE!>_<!>)<!>
<!INITIALIZER_REQUIRED_FOR_DESTRUCTURING_DECLARATION!>val (@A a, <!UNDERSCORE_IS_RESERVED, UNUSED_VARIABLE!>_<!>)<!>
}
annotation class A
@@ -7,7 +7,7 @@ class C {
}
fun test1(c: C) {
val (<!UNUSED_VARIABLE!>a<!>, <!UNUSED_VARIABLE!>b<!>) = c
val (a, <!UNUSED_VARIABLE!>b<!>) = c
}
fun test2(c: C) {
@@ -16,7 +16,7 @@ fun test2(c: C) {
}
fun test3(c: C) {
var (<!ASSIGNED_BUT_NEVER_ACCESSED_VARIABLE!>a<!>, <!UNUSED_VARIABLE!>b<!>) = c
var (a, <!UNUSED_VARIABLE!>b<!>) = c
<!UNUSED_VALUE!>a =<!> 3
}
@@ -6,7 +6,7 @@ class A {
fun foo(a: A, c: Int) {
val (<!NAME_SHADOWING!>a<!>, b) = a
val arr = Array(2) { A() }
for ((<!NAME_SHADOWING!>c<!>, d) in arr) {
for ((<!NAME_SHADOWING!>c<!>, <!UNUSED_VARIABLE!>d<!>) in arr) {
}