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
@@ -578,6 +578,7 @@ class ControlFlowInformationProvider private constructor(
}
else if (element is KtParameter) {
val owner = element.parent?.parent
if (element.isSingleUnderscore) return@traverse
when (owner) {
is KtPrimaryConstructor -> if (!element.hasValOrVar()) {
val containingClass = owner.getContainingClassOrObject()
@@ -590,7 +591,6 @@ class ControlFlowInformationProvider private constructor(
is KtFunction -> {
val mainFunctionDetector = MainFunctionDetector(trace.bindingContext)
val isMain = owner is KtNamedFunction && mainFunctionDetector.isMain(owner)
if (owner is KtFunctionLiteral) return@traverse
val functionDescriptor =
trace.get(BindingContext.DECLARATION_TO_DESCRIPTOR, owner) as? FunctionDescriptor
?: throw AssertionError(owner.text)
@@ -42,7 +42,6 @@ import org.jetbrains.kotlin.parsing.KotlinExpressionParsing;
import org.jetbrains.kotlin.psi.psiUtil.KtPsiUtilKt;
import org.jetbrains.kotlin.resolve.StatementFilter;
import org.jetbrains.kotlin.resolve.StatementFilterKt;
import org.jetbrains.kotlin.types.expressions.OperatorConventions;
import java.util.Collection;
import java.util.HashSet;
@@ -280,9 +279,8 @@ public class KtPsiUtil {
if (!(declaration instanceof KtVariableDeclaration)) return false;
if (declaration instanceof KtProperty) return true;
assert declaration instanceof KtDestructuringDeclarationEntry;
KtDestructuringDeclaration parentDeclaration = (KtDestructuringDeclaration) declaration.getParent();
List<KtDestructuringDeclarationEntry> entries = parentDeclaration.getEntries();
return entries.size() > 1 && entries.get(entries.size() - 1) == declaration;
// We can always replace destructuring entry with _
return true;
}
@Nullable
+2 -2
View File
@@ -4,7 +4,7 @@ fun text() {
"direct:a" on {it -> it.body == "<hello/>"} to "mock:a"
bar <!EXPECTED_PARAMETERS_NUMBER_MISMATCH!>{<!>1}
bar <!EXPECTED_PARAMETERS_NUMBER_MISMATCH!>{<!><!UNRESOLVED_REFERENCE!>it<!> <!DEBUG_INFO_ELEMENT_WITH_ERROR_TYPE!>+<!> 1}
bar {it, it1 -> it}
bar {it, <!UNUSED_PARAMETER!>it1<!> -> it}
bar1 {1}
bar1 {it + 1}
@@ -29,4 +29,4 @@ infix fun String.on(<!UNUSED_PARAMETER!>predicate<!> : (s : URI) -> Boolean) :
class URI(val body : Any) {
infix fun to(<!UNUSED_PARAMETER!>dest<!> : String) {}
}
}
@@ -36,8 +36,8 @@ fun main(args : Array<String>) {
foo2()({})
foo2()<!TOO_MANY_ARGUMENTS!>{}<!>
(foo2()){}
(foo2()){<!EXPECTED_PARAMETERS_NUMBER_MISMATCH, CANNOT_INFER_PARAMETER_TYPE!>x<!> -> }
foo2()({<!EXPECTED_PARAMETERS_NUMBER_MISMATCH, CANNOT_INFER_PARAMETER_TYPE!>x<!> -> })
(foo2()){<!EXPECTED_PARAMETERS_NUMBER_MISMATCH, CANNOT_INFER_PARAMETER_TYPE, UNUSED_PARAMETER!>x<!> -> }
foo2()({<!EXPECTED_PARAMETERS_NUMBER_MISMATCH, CANNOT_INFER_PARAMETER_TYPE, UNUSED_PARAMETER!>x<!> -> })
val a = fooT1(1)()
checkSubtype<Int>(a)
@@ -72,7 +72,7 @@ fun main1() {
}
fun test() {
{x : Int -> 1}(<!NO_VALUE_FOR_PARAMETER!>)<!>;
{<!UNUSED_PARAMETER!>x<!> : Int -> 1}(<!NO_VALUE_FOR_PARAMETER!>)<!>;
(fun Int.() = 1)(<!NO_VALUE_FOR_PARAMETER!>)<!>
<!TYPE_MISMATCH!>"sd"<!>.(fun Int.() = 1)()
val i : Int? = null
@@ -80,4 +80,4 @@ fun test() {
{}<!WRONG_NUMBER_OF_TYPE_ARGUMENTS!><Int><!>()
1<!UNNECESSARY_SAFE_CALL!>?.<!>(fun Int.() = 1)()
1.<!NO_RECEIVER_ALLOWED!>{}<!>()
}
}
+1 -1
View File
@@ -23,7 +23,7 @@ fun <!UNDERSCORE_IS_RESERVED!>__<!>(<!UNDERSCORE_IS_RESERVED!>___<!>: Int, y: _<
}
// one underscore parameters for named function are still prohibited
fun oneUnderscore(<!UNUSED_PARAMETER, UNDERSCORE_IS_RESERVED!>_<!>: Int) {}
fun oneUnderscore(<!UNDERSCORE_IS_RESERVED!>_<!>: Int) {}
fun doIt(f: (Any?) -> Any?) = f(null)
@@ -1,6 +1,6 @@
data class D(val x: Int, val y: Int, val z: Int)
fun foo(): Int {
val (x, y, z) = D(1, 2, 3)
val (<!UNUSED_VARIABLE!>x<!>, y, z) = D(1, 2, 3)
return y + z // x is not used, but we cannot do anything with it
}
fun bar(): Int {
@@ -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) <!UNUSED_VARIABLE!>y<!>) in bar()) {}
for (<!WRONG_ANNOTATION_TARGET!>@Ann(3)<!> (<!UNUSED_VARIABLE!>x<!>, @Ann(4) <!UNUSED_VARIABLE!>y<!>) in bar()) {}
for (@<!UNRESOLVED_REFERENCE!>Err<!>() (x,<!UNUSED_VARIABLE!>y<!>) in bar()) {}
}
for (@<!UNRESOLVED_REFERENCE!>Err<!>() (<!UNUSED_VARIABLE!>x<!>,<!UNUSED_VARIABLE!>y<!>) in bar()) {}
}
@@ -22,11 +22,11 @@ fun f() {
}
for (<!VAL_OR_VAR_ON_LOOP_PARAMETER!>val<!> (i,<!UNUSED_VARIABLE!>j<!>) in Coll()) {
for (<!VAL_OR_VAR_ON_LOOP_PARAMETER!>val<!> (<!UNUSED_VARIABLE!>i<!>,<!UNUSED_VARIABLE!>j<!>) in Coll()) {
}
for (<!VAL_OR_VAR_ON_LOOP_PARAMETER!>var<!> (i,<!UNUSED_VARIABLE!>j<!>) in Coll()) {
for (<!VAL_OR_VAR_ON_LOOP_PARAMETER!>var<!> (<!UNUSED_VARIABLE!>i<!>,<!UNUSED_VARIABLE!>j<!>) in Coll()) {
}
}
@@ -4,5 +4,5 @@ class A {
}
fun a(aa : A) {
val (a: String, <!UNUSED_VARIABLE!>b1<!>: String) = <!COMPONENT_FUNCTION_RETURN_TYPE_MISMATCH, COMPONENT_FUNCTION_RETURN_TYPE_MISMATCH!>aa<!>
}
val (<!UNUSED_VARIABLE!>a<!>: String, <!UNUSED_VARIABLE!>b1<!>: String) = <!COMPONENT_FUNCTION_RETURN_TYPE_MISMATCH, COMPONENT_FUNCTION_RETURN_TYPE_MISMATCH!>aa<!>
}
@@ -8,7 +8,7 @@ class A {
}
fun foo(list: List<A>) {
for (<!VAL_OR_VAR_ON_LOOP_PARAMETER!>var<!> (c1, c2, c3) in list) {
for (<!VAL_OR_VAR_ON_LOOP_PARAMETER!>var<!> (<!ASSIGNED_BUT_NEVER_ACCESSED_VARIABLE!>c1<!>, <!UNUSED_VARIABLE!>c2<!>, c3) in list) {
<!UNUSED_VALUE!><!VAL_REASSIGNMENT!>c1<!> =<!> 1
c3 + 1
}
@@ -5,10 +5,10 @@ class A {
fun a(aa : A?, b : Any) {
if (aa != null) {
val (a1, <!UNUSED_VARIABLE!>b1<!>) = <!DEBUG_INFO_SMARTCAST!>aa<!>;
val (<!UNUSED_VARIABLE!>a1<!>, <!UNUSED_VARIABLE!>b1<!>) = <!DEBUG_INFO_SMARTCAST!>aa<!>;
}
if (b is A) {
val (a1, <!UNUSED_VARIABLE!>b1<!>) = <!DEBUG_INFO_SMARTCAST!>b<!>;
val (<!UNUSED_VARIABLE!>a1<!>, <!UNUSED_VARIABLE!>b1<!>) = <!DEBUG_INFO_SMARTCAST!>b<!>;
}
}
}
@@ -4,11 +4,11 @@ class A {
}
fun a() {
val (<!REDECLARATION!>a<!>, <!NAME_SHADOWING, REDECLARATION, UNUSED_VARIABLE!>a<!>) = A()
val (x, <!REDECLARATION, UNUSED_VARIABLE!>y<!>) = A();
val (<!REDECLARATION, UNUSED_VARIABLE!>a<!>, <!NAME_SHADOWING, REDECLARATION, UNUSED_VARIABLE!>a<!>) = A()
val (<!UNUSED_VARIABLE!>x<!>, <!REDECLARATION, UNUSED_VARIABLE!>y<!>) = A();
val <!REDECLARATION!>b<!> = 1
use(b)
val (<!NAME_SHADOWING, REDECLARATION!>b<!>, <!NAME_SHADOWING, REDECLARATION, UNUSED_VARIABLE!>y<!>) = A();
val (<!NAME_SHADOWING, REDECLARATION, UNUSED_VARIABLE!>b<!>, <!NAME_SHADOWING, REDECLARATION, UNUSED_VARIABLE!>y<!>) = A();
}
@@ -8,7 +8,7 @@ class C {
}
fun test() {
for ((x, <!UNUSED_VARIABLE!>y<!>) in C()) {
for ((<!UNUSED_VARIABLE!>x<!>, <!UNUSED_VARIABLE!>y<!>) in C()) {
}
}
@@ -8,7 +8,7 @@ class C {
}
fun test() {
for ((x: Double, <!UNUSED_VARIABLE!>y<!>: Int) in <!COMPONENT_FUNCTION_RETURN_TYPE_MISMATCH, COMPONENT_FUNCTION_RETURN_TYPE_MISMATCH!>C()<!>) {
for ((<!UNUSED_VARIABLE!>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, <!UNUSED_VARIABLE!>y<!>) in <!COMPONENT_FUNCTION_AMBIGUITY!>C()<!>) {
for ((<!UNUSED_VARIABLE!>x<!>, <!UNUSED_VARIABLE!>y<!>) in <!COMPONENT_FUNCTION_AMBIGUITY!>C()<!>) {
}
}
}
@@ -7,7 +7,7 @@ class C {
}
fun test() {
for ((x, <!UNUSED_VARIABLE!>y<!>) in <!COMPONENT_FUNCTION_MISSING!>C()<!>) {
for ((<!UNUSED_VARIABLE!>x<!>, <!UNUSED_VARIABLE!>y<!>) in <!COMPONENT_FUNCTION_MISSING!>C()<!>) {
}
}
@@ -6,7 +6,7 @@ fun useDeclaredVariables() {
}
fun checkersShouldRun() {
for ((@A a, _)<!SYNTAX!><!>) {
for ((@A <!UNUSED_VARIABLE!>a<!>, _)<!SYNTAX!><!>) {
}
}
@@ -8,7 +8,7 @@ class C {
}
fun test() {
for ((x, <!UNUSED_VARIABLE!>y<!>) in C()) {
for ((<!UNUSED_VARIABLE!>x<!>, <!UNUSED_VARIABLE!>y<!>) in C()) {
}
}
@@ -8,7 +8,7 @@ class C {
}
fun test() {
for ((x: Int, <!UNUSED_VARIABLE!>y<!>: Double) in C()) {
for ((<!UNUSED_VARIABLE!>x<!>: Int, <!UNUSED_VARIABLE!>y<!>: Double) in C()) {
}
}
@@ -8,7 +8,7 @@ class C {
}
fun test() {
for ((<!REDECLARATION!>x<!>, <!NAME_SHADOWING, REDECLARATION, UNUSED_VARIABLE!>x<!>) in C()) {
for ((<!REDECLARATION, UNUSED_VARIABLE!>x<!>, <!NAME_SHADOWING, REDECLARATION, UNUSED_VARIABLE!>x<!>) in C()) {
}
}
@@ -7,7 +7,7 @@ class C {
}
fun test() {
for ((x) in C()) {
for ((<!UNUSED_VARIABLE!>x<!>) in C()) {
}
}
}
@@ -5,7 +5,7 @@ fun useDeclaredVariables() {
}
fun checkersShouldRun() {
val (@A a, _) = <!UNRESOLVED_REFERENCE!>unresolved<!>
val (@A <!UNUSED_VARIABLE!>a<!>, _) = <!UNRESOLVED_REFERENCE!>unresolved<!>
}
annotation class A
@@ -5,7 +5,7 @@ fun useDeclaredVariables() {
}
fun checkersShouldRun() {
<!INITIALIZER_REQUIRED_FOR_DESTRUCTURING_DECLARATION!>val (@A a, _)<!>
<!INITIALIZER_REQUIRED_FOR_DESTRUCTURING_DECLARATION!>val (@A <!UNUSED_VARIABLE!>a<!>, _)<!>
}
annotation class A
@@ -43,6 +43,8 @@ fun test() {
val (_, <!NAME_SHADOWING, REDECLARATION!>`_`<!>) = A()
foo(<!TYPE_MISMATCH!>_<!>, y)
val (<!UNUSED_VARIABLE!>unused<!>, _) = A()
}
fun foo(<!UNUSED_PARAMETER!>x<!>: Int, <!UNUSED_PARAMETER!>y<!>: String) {}
@@ -7,7 +7,7 @@ class C {
}
fun test1(c: C) {
val (a, <!UNUSED_VARIABLE!>b<!>) = c
val (<!UNUSED_VARIABLE!>a<!>, <!UNUSED_VARIABLE!>b<!>) = c
}
fun test2(c: C) {
@@ -16,7 +16,7 @@ fun test2(c: C) {
}
fun test3(c: C) {
var (a, <!UNUSED_VARIABLE!>b<!>) = c
var (<!ASSIGNED_BUT_NEVER_ACCESSED_VARIABLE!>a<!>, <!UNUSED_VARIABLE!>b<!>) = c
<!UNUSED_VALUE!>a =<!> 3
}
@@ -24,4 +24,4 @@ fun test4(c: C) {
var (<!VARIABLE_WITH_REDUNDANT_INITIALIZER!>a<!>, <!UNUSED_VARIABLE!>b<!>) = c
a = 3
a + 1
}
}
@@ -17,8 +17,8 @@ val none = { -> }
val parameterWithFunctionType = { a: ((Int) -> Int) -> <!SYNTAX!><!>} // todo fix parser
val newSyntax = { a: Int -> }
val newSyntax1 = { <!CANNOT_INFER_PARAMETER_TYPE!>a<!>, <!CANNOT_INFER_PARAMETER_TYPE!>b<!> -> }
val newSyntax2 = { a: Int, b: Int -> }
val newSyntax3 = { <!CANNOT_INFER_PARAMETER_TYPE!>a<!>, b: Int -> }
val newSyntax4 = { a: Int, <!CANNOT_INFER_PARAMETER_TYPE!>b<!> -> }
val newSyntax = { <!UNUSED_PARAMETER!>a<!>: Int -> }
val newSyntax1 = { <!CANNOT_INFER_PARAMETER_TYPE, UNUSED_PARAMETER!>a<!>, <!CANNOT_INFER_PARAMETER_TYPE, UNUSED_PARAMETER!>b<!> -> }
val newSyntax2 = { <!UNUSED_PARAMETER!>a<!>: Int, <!UNUSED_PARAMETER!>b<!>: Int -> }
val newSyntax3 = { <!CANNOT_INFER_PARAMETER_TYPE, UNUSED_PARAMETER!>a<!>, <!UNUSED_PARAMETER!>b<!>: Int -> }
val newSyntax4 = { <!UNUSED_PARAMETER!>a<!>: Int, <!CANNOT_INFER_PARAMETER_TYPE, UNUSED_PARAMETER!>b<!> -> }
@@ -9,20 +9,20 @@ fun test1() {
""
}
foo0 {
<!EXPECTED_PARAMETERS_NUMBER_MISMATCH!>s: String<!>-> ""
<!EXPECTED_PARAMETERS_NUMBER_MISMATCH!><!UNUSED_PARAMETER!>s<!>: String<!>-> ""
}
foo0 {
<!EXPECTED_PARAMETERS_NUMBER_MISMATCH!><!CANNOT_INFER_PARAMETER_TYPE!>x<!>, <!CANNOT_INFER_PARAMETER_TYPE!>y<!><!> -> ""
<!EXPECTED_PARAMETERS_NUMBER_MISMATCH!><!CANNOT_INFER_PARAMETER_TYPE, UNUSED_PARAMETER!>x<!>, <!CANNOT_INFER_PARAMETER_TYPE, UNUSED_PARAMETER!>y<!><!> -> ""
}
foo1 {
""
}
foo1 {
<!EXPECTED_PARAMETER_TYPE_MISMATCH!>s: String<!> -> ""
<!EXPECTED_PARAMETER_TYPE_MISMATCH!><!UNUSED_PARAMETER!>s<!>: String<!> -> ""
}
foo1 {
<!EXPECTED_PARAMETERS_NUMBER_MISMATCH!>x, <!CANNOT_INFER_PARAMETER_TYPE!>y<!><!> -> ""
<!EXPECTED_PARAMETERS_NUMBER_MISMATCH!><!UNUSED_PARAMETER!>x<!>, <!CANNOT_INFER_PARAMETER_TYPE, UNUSED_PARAMETER!>y<!><!> -> ""
}
foo1 {
<!EXPECTED_PARAMETERS_NUMBER_MISMATCH!><!>-> <!CONSTANT_EXPECTED_TYPE_MISMATCH!>42<!>
@@ -33,12 +33,12 @@ fun test1() {
""
}
foo2 {
<!EXPECTED_PARAMETERS_NUMBER_MISMATCH, EXPECTED_PARAMETER_TYPE_MISMATCH!>s: String<!> -> ""
<!EXPECTED_PARAMETERS_NUMBER_MISMATCH, EXPECTED_PARAMETER_TYPE_MISMATCH!><!UNUSED_PARAMETER!>s<!>: String<!> -> ""
}
foo2 {
<!EXPECTED_PARAMETERS_NUMBER_MISMATCH!>x<!> -> ""
<!EXPECTED_PARAMETERS_NUMBER_MISMATCH, UNUSED_PARAMETER!>x<!> -> ""
}
foo2 {
<!EXPECTED_PARAMETERS_NUMBER_MISMATCH!><!>-> <!CONSTANT_EXPECTED_TYPE_MISMATCH!>42<!>
}
}
}
@@ -1,8 +1,7 @@
// !CHECK_TYPE
// !DIAGNOSTICS: -UNUSED_PARAMETER
fun foo(block: (Int, String) -> Unit) { }
fun foobar(block: (Double) -> Unit) { }
fun foo(<!UNUSED_PARAMETER!>block<!>: (Int, String) -> Unit) { }
fun foobar(<!UNUSED_PARAMETER!>block<!>: (Double) -> Unit) { }
fun bar() {
foo { _, b ->
@@ -41,9 +40,9 @@ fun bar() {
_ checkType { _<String>() }
}
foo { <!REDECLARATION, REDECLARATION!>`_`<!>, <!REDECLARATION, REDECLARATION!>`_`<!> ->
foo { <!REDECLARATION, REDECLARATION, UNUSED_PARAMETER!>`_`<!>, <!REDECLARATION, REDECLARATION!>`_`<!> ->
_ checkType { _<String>() }
}
foo(fun(x: Int, _: String) {})
foo(fun(<!UNUSED_PARAMETER!>x<!>: Int, _: String) {})
}
@@ -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
}
+2 -2
View File
@@ -1,6 +1,6 @@
inline fun foo(f: () -> Unit) {
val ff = { f: () -> Unit ->
f.invoke()
}
ff(<!USAGE_IS_NOT_INLINABLE!>f<!>)
}
}
@@ -19,32 +19,32 @@ public class A {
// FILE: main.kt
fun main() {
A().foo {
x -> 1
x -> x.hashCode()
}
A.bar {
x -> 1
x -> x.hashCode()
}
// baz
A.baz {
x -> "" // OK
x -> x.toString() // OK
}
A.baz {
x -> <!CONSTANT_EXPECTED_TYPE_MISMATCH!>1<!>
x -> <!TYPE_MISMATCH!>x.hashCode()<!>
}
val block: (String) -> Any? = {
x -> 1
x -> x.hashCode()
}
A().foo(block)
A.bar(block)
val block2: (String) -> CharSequence? = {
x -> ""
x -> x.toString()
}
A.<!NONE_APPLICABLE!>baz<!>(block)
@@ -16,12 +16,12 @@ public class A {
// FILE: main.kt
fun main() {
A().foo <!TYPE_MISMATCH!>{
<!CANNOT_INFER_PARAMETER_TYPE!>x<!> ->
<!CANNOT_INFER_PARAMETER_TYPE, UNUSED_PARAMETER!>x<!> ->
""
}<!>
A.bar <!TYPE_MISMATCH!>{
<!CANNOT_INFER_PARAMETER_TYPE!>x<!> ->
<!CANNOT_INFER_PARAMETER_TYPE, UNUSED_PARAMETER!>x<!> ->
""
}<!>
}
@@ -27,7 +27,7 @@ fun main() {
""
}
val block: (Map<String, Int>) -> CharSequence = { x -> "" }
val block: (Map<String, Int>) -> CharSequence = { x -> x.toString() }
A().foo(block)
A.bar(block)
}
@@ -23,5 +23,5 @@ fun main() {
B().foo(<!TYPE_MISMATCH!>{ println() }<!>, B.bar())
// So you should use SAM constructors when you want to use mix lambdas and Java objects
B().foo(Runnable { println() }, B.bar())
B().foo({ println() }, { it: Any? -> true } )
B().foo({ println() }, { it: Any? -> it == null } )
}
@@ -1,4 +1,4 @@
// !DIAGNOSTICS: -UNUSED_VARIABLE
// !DIAGNOSTICS: -UNUSED_VARIABLE -UNUSED_PARAMETER
// FILE: A.java
import java.util.Comparator;
+1 -1
View File
@@ -3,6 +3,6 @@ fun foo1() : (Int) -> Int = { x: Int -> x }
fun foo() {
val h : (Int) -> Int = foo1();
h(1)
val m : (Int) -> Int = {a : Int -> 1}//foo1()
val m : (Int) -> Int = {<!UNUSED_PARAMETER!>a<!> : Int -> 1}//foo1()
m(1)
}
@@ -6,9 +6,9 @@ class A {
fun foo(a: A, c: Int) {
val (<!NAME_SHADOWING!>a<!>, b) = a
val arr = Array(2) { A() }
for ((<!NAME_SHADOWING!>c<!>, <!UNUSED_VARIABLE!>d<!>) in arr) {
for ((<!NAME_SHADOWING, UNUSED_VARIABLE!>c<!>, <!UNUSED_VARIABLE!>d<!>) in arr) {
}
val <!UNUSED_VARIABLE!>e<!> = a.toString() + b + c
}
}
@@ -1,6 +1,6 @@
// FILE: KotlinFile.kt
fun foo(javaClass: JavaClass<String>): String {
return javaClass.doSomething("", 1) { s: String -> "" }
return javaClass.doSomething("", 1) { <!UNUSED_PARAMETER!>s<!>: String -> "" }
}
// FILE: JavaClass.java
@@ -10,4 +10,4 @@ public class JavaClass<T> {
interface I<T> {
T doIt(T t);
}
}
@@ -12,13 +12,13 @@ val test2: (String) -> Boolean =
val test3: (String) -> Boolean =
when {
true -> { s -> true }
true -> { <!UNUSED_PARAMETER!>s<!> -> true }
else -> null!!
}
val test4: (String) -> Boolean =
when {
true -> { <!EXPECTED_PARAMETERS_NUMBER_MISMATCH!>s1, <!CANNOT_INFER_PARAMETER_TYPE!>s2<!><!> -> true }
true -> { <!EXPECTED_PARAMETERS_NUMBER_MISMATCH!><!UNUSED_PARAMETER!>s1<!>, <!CANNOT_INFER_PARAMETER_TYPE, UNUSED_PARAMETER!>s2<!><!> -> true }
else -> null!!
}
@@ -1,3 +1,4 @@
// !DIAGNOSTICS: -UNUSED_PARAMETER
// !CHECK_TYPE
fun test(d: dynamic) {
@@ -1,3 +1,4 @@
// !DIAGNOSTICS: -UNUSED_PARAMETER
import kotlin.properties.Delegates
class My {
@@ -6,4 +7,4 @@ class My {
// Both Ok
@get:JvmSynthetic val t: String by lazy { "t" }
@set:JvmSynthetic var z: String by Delegates.observable("?") { prop, old, new -> old.hashCode() }
}
}
@@ -1,3 +1,4 @@
// !DIAGNOSTICS: -UNUSED_PARAMETER
import kotlin.jvm.Volatile
import kotlin.properties.Delegates
@@ -9,4 +10,4 @@ class My {
<!VOLATILE_ON_DELEGATE!>@delegate:Volatile<!> var z: String by Delegates.observable("?") { prop, old, new -> old.hashCode() }
<!VOLATILE_ON_VALUE!>@field:Volatile<!> val w = 2
}
}
@@ -33,8 +33,8 @@ private val STRING = CompileTimeType<String>()
private val ANY = CompileTimeType<Any>()
private val emptyBinaryFun: Function2<BigInteger, BigInteger, BigInteger> = { a, b -> BigInteger("0") }
private val emptyUnaryFun: Function1<Long, Long> = { a -> 1.toLong() }
private val emptyBinaryFun: Function2<BigInteger, BigInteger, BigInteger> = { <!UNUSED_PARAMETER!>a<!>, <!UNUSED_PARAMETER!>b<!> -> BigInteger("0") }
private val emptyUnaryFun: Function1<Long, Long> = { <!UNUSED_PARAMETER!>a<!> -> 1.toLong() }
private val unaryOperations: HashMap<UnaryOperationKey<*>, Pair<Function1<Any?, Any>, Function1<Long, Long>>>
= hashMapOf<UnaryOperationKey<*>, Pair<Function1<Any?, Any>, Function1<Long, Long>>>(
@@ -368,4 +368,4 @@ class BigInteger(val value: String) {
fun or(o: BigInteger): BigInteger = o
fun and(o: BigInteger): BigInteger = o
fun xor(o: BigInteger): BigInteger = o
}
}
+7 -7
View File
@@ -5,15 +5,15 @@ class A {
fun arrayA(): Array<A> = null!!
fun foo(a: A, <warning>c</warning>: Int) {
val (<warning descr="[NAME_SHADOWING] Name shadowed: a">a</warning>, <warning>b</warning>) = a
fun foo(a: A, <warning descr="[UNUSED_PARAMETER] Parameter 'c' is never used">c</warning>: Int) {
val (<warning descr="[NAME_SHADOWING] Name shadowed: a"><warning descr="[UNUSED_VARIABLE] Variable 'a' is never used">a</warning></warning>, <warning descr="[UNUSED_VARIABLE] Variable 'b' is never used">b</warning>) = a
val arr = arrayA()
for ((<warning descr="[NAME_SHADOWING] Name shadowed: c">c</warning>, <warning>d</warning>) in arr) {
for ((<warning descr="[NAME_SHADOWING] Name shadowed: c"><warning descr="[UNUSED_VARIABLE] Variable 'c' is never used">c</warning></warning>, <warning descr="[UNUSED_VARIABLE] Variable 'd' is never used">d</warning>) in arr) {
}
}
fun f(<warning>p</warning>: Int): Int {
val <error>p</error> = 2
val <error>p</error> = 3
fun f(<warning descr="[UNUSED_PARAMETER] Parameter 'p' is never used">p</warning>: Int): Int {
val <error descr="">p</error> = 2
val <error descr="">p</error> = 3
return p
}
}
@@ -1,3 +1,3 @@
fun main() {
for ((i, <warning>j</warning>)<error>)</error> {}
}
for ((<warning>i</warning>, <warning>j</warning>)<error>)</error> {}
}
+2 -2
View File
@@ -3,6 +3,6 @@ fun foo1() : (Int) -> Int = { x: Int -> x }
fun foo() {
val h : (Int) -> Int = foo1();
h(1)
val m : (Int) -> Int = {a : Int -> 1}//foo1()
val m : (Int) -> Int = {<warning descr="[UNUSED_PARAMETER] Parameter 'a' is never used">a</warning> : Int -> 1}//foo1()
m(1)
}
}