Report warning on unused entities that can be renamed to _

Currently it's all about lambda parameters/destructuring entries

 #KT-14347 In Progress
This commit is contained in:
Denis Zharkov
2016-10-13 16:44:27 +03:00
parent a9fcee098d
commit 4c69416f2b
56 changed files with 123 additions and 121 deletions
@@ -3,4 +3,4 @@ package f
fun <R> h(<!UNUSED_PARAMETER!>i<!>: Int, <!UNUSED_PARAMETER!>a<!>: Any, <!UNUSED_PARAMETER!>r<!>: R, <!UNUSED_PARAMETER!>f<!>: (Boolean) -> Int) = 1
fun <R> h(<!UNUSED_PARAMETER!>a<!>: Any, <!UNUSED_PARAMETER!>i<!>: Int, <!UNUSED_PARAMETER!>r<!>: R, <!UNUSED_PARAMETER!>f<!>: (Boolean) -> Int) = 1
fun test() = <!CANNOT_COMPLETE_RESOLVE!>h<!>(1, 1, 1, { <!CANNOT_INFER_PARAMETER_TYPE!>b<!> -> 42 })
fun test() = <!CANNOT_COMPLETE_RESOLVE!>h<!>(1, 1, 1, { <!CANNOT_INFER_PARAMETER_TYPE, UNUSED_PARAMETER!>b<!> -> 42 })
@@ -4,7 +4,7 @@ package f
fun <R> h(<!UNUSED_PARAMETER!>f<!>: (Boolean) -> R) = 1
fun <R> h(<!UNUSED_PARAMETER!>f<!>: (String) -> R) = 2
fun test() = <!CANNOT_COMPLETE_RESOLVE!>h<!>{ <!CANNOT_INFER_PARAMETER_TYPE!>i<!> -> getAnswer() }
fun test() = <!CANNOT_COMPLETE_RESOLVE!>h<!>{ <!CANNOT_INFER_PARAMETER_TYPE, UNUSED_PARAMETER!>i<!> -> getAnswer() }
fun getAnswer() = 42
@@ -5,10 +5,10 @@ import java.util.*
import java.util.Collections.*
fun foo(list: List<String>) : String {
val w : String = max(list, comparator<String?> {o1, o2 -> 1
val w : String = max(list, comparator<String?> {<!UNUSED_PARAMETER!>o1<!>, <!UNUSED_PARAMETER!>o2<!> -> 1
})
return w
}
//from library
fun <T> comparator(<!UNUSED_PARAMETER!>fn<!>: (T,T) -> Int): Comparator<T> {<!NO_RETURN_IN_FUNCTION_WITH_BLOCK_BODY!>}<!>
fun <T> comparator(<!UNUSED_PARAMETER!>fn<!>: (T,T) -> Int): Comparator<T> {<!NO_RETURN_IN_FUNCTION_WITH_BLOCK_BODY!>}<!>
@@ -9,5 +9,5 @@ fun <A, B> Foo<A>.map(<!UNUSED_PARAMETER!>f<!>: (A) -> B): Foo<B> = object : Foo
fun foo() {
val l: Foo<String> = object : Foo<String> {}
val <!UNUSED_VARIABLE!>m<!>: Foo<String> = l.<!TYPE_INFERENCE_EXPECTED_TYPE_MISMATCH!>map { ppp -> 1 }<!>
}
val <!UNUSED_VARIABLE!>m<!>: Foo<String> = l.<!TYPE_INFERENCE_EXPECTED_TYPE_MISMATCH!>map { <!UNUSED_PARAMETER!>ppp<!> -> 1 }<!>
}
@@ -7,5 +7,5 @@ fun <T> _arrayList(vararg <!UNUSED_PARAMETER!>values<!>: T) : List<T> = throw Ex
class _Pair<A>(val a: A)
fun test() {
_arrayList(_Pair(1))._sortBy { it -> <!UNRESOLVED_REFERENCE!>xxx<!> }
}
_arrayList(_Pair(1))._sortBy { <!UNUSED_PARAMETER!>it<!> -> <!UNRESOLVED_REFERENCE!>xxx<!> }
}
@@ -9,7 +9,7 @@ public inline fun <T: Closeable, R> T.use1(block: (T)-> R) : R {
fun main(args: Array<String>) {
C().use1 {
w -> // ERROR here
<!UNUSED_PARAMETER!>w<!> -> // ERROR here
<!UNRESOLVED_REFERENCE!>x<!>
}
}
}
@@ -8,7 +8,7 @@ enum class SomeEnum {
// Doesn't work
fun Iterable<Int>.some() {
this.fold(SomeEnum.FIRST, {res : SomeEnum, value ->
this.fold(SomeEnum.FIRST, {res : SomeEnum, <!UNUSED_PARAMETER!>value<!> ->
if (res == SomeEnum.FIRST) SomeEnum.FIRST else SomeEnum.SECOND
})
}
@@ -19,7 +19,7 @@ fun tempFun() : SomeEnum {
// Doesn't work
fun Iterable<Int>.someSimpleWithFun() {
this.fold(SomeEnum.FIRST, {res : SomeEnum, value ->
this.fold(SomeEnum.FIRST, {<!UNUSED_PARAMETER!>res<!> : SomeEnum, <!UNUSED_PARAMETER!>value<!> ->
tempFun()
})
}
@@ -27,17 +27,17 @@ fun Iterable<Int>.someSimpleWithFun() {
// Works
fun Iterable<Int>.someSimple() {
this.fold(SomeEnum.FIRST, {res : SomeEnum, value ->
this.fold(SomeEnum.FIRST, {<!UNUSED_PARAMETER!>res<!> : SomeEnum, <!UNUSED_PARAMETER!>value<!> ->
SomeEnum.FIRST
})
}
// Works
fun Iterable<Int>.someInt() {
this.fold(0, {res : Int, value ->
this.fold(0, {res : Int, <!UNUSED_PARAMETER!>value<!> ->
if (res == 0) 1 else 0
})
}
//from standard library
fun <T,R> Iterable<T>.fold(<!UNUSED_PARAMETER!>initial<!>: R, <!UNUSED_PARAMETER!>operation<!>: (R, T) -> R): R {<!NO_RETURN_IN_FUNCTION_WITH_BLOCK_BODY!>}<!>
fun <T,R> Iterable<T>.fold(<!UNUSED_PARAMETER!>initial<!>: R, <!UNUSED_PARAMETER!>operation<!>: (R, T) -> R): R {<!NO_RETURN_IN_FUNCTION_WITH_BLOCK_BODY!>}<!>
@@ -15,10 +15,10 @@ fun SomeTemplate.query(f: (i: Int) -> Unit) = f
fun SomeTemplate.query1(f: (i: Int) -> Unit) = f
fun test() {
val mapperFunction = { i: Int -> }
val mapperFunction = { <!UNUSED_PARAMETER!>i<!>: Int -> }
SomeTemplate().query(mapperFunction)
// TYPE_MISMATCH: Required Class<[ERROR: CANT_INFER]>, Found (kotlin.Int) -> Unit
SomeTemplate().query { i: Int -> }
SomeTemplate().query1 { i: Int -> }
SomeTemplate().query { <!UNUSED_PARAMETER!>i<!>: Int -> }
SomeTemplate().query1 { <!UNUSED_PARAMETER!>i<!>: Int -> }
}
@@ -3,7 +3,7 @@ package a
fun <T, R, S> foo(block: (T)-> R, <!UNUSED_PARAMETER!>second<!>: (T)-> S) = block
fun main(args: Array<String>) {
val fff = { x: Int -> <!UNRESOLVED_REFERENCE!>aaa<!> }
val fff = { <!UNUSED_PARAMETER!>x<!>: Int -> <!UNRESOLVED_REFERENCE!>aaa<!> }
foo(<!DEBUG_INFO_ELEMENT_WITH_ERROR_TYPE!>fff<!>, { x -> x + 1 })
}
@@ -9,7 +9,7 @@ fun <T: Closeable, R> T.foo(block: (T, T)-> R) = block
fun main(args: Array<String>) {
C().foo { // no ambiguity here
www ->
<!UNUSED_PARAMETER!>www<!> ->
<!UNRESOLVED_REFERENCE!>xs<!>
}
}
@@ -4,7 +4,7 @@ fun <T, R> foo(block: (T)-> R) = block
fun test1() {
<!TYPE_INFERENCE_NO_INFORMATION_FOR_PARAMETER!>foo<!> {
<!CANNOT_INFER_PARAMETER_TYPE!>x<!> -> // here we have 'cannot infer parameter type' error
<!CANNOT_INFER_PARAMETER_TYPE, UNUSED_PARAMETER!>x<!> -> // here we have 'cannot infer parameter type' error
43
}
}
@@ -12,5 +12,5 @@ fun test1() {
fun bar(<!UNUSED_PARAMETER!>f<!>: (<!UNRESOLVED_REFERENCE!>A<!>)->Unit) {}
fun test2() {
bar { a -> } // here we don't have 'cannot infer parameter type' error
}
bar { <!UNUSED_PARAMETER!>a<!> -> } // here we don't have 'cannot infer parameter type' error
}