KT-1191 Wrong detection of unused parameters

KT-1219 Incorrect 'unused value' error in closures
This commit is contained in:
Svetlana Isakova
2012-02-22 17:07:49 +04:00
parent 7f2a8100c4
commit cc244fad94
12 changed files with 94 additions and 22 deletions
@@ -328,7 +328,7 @@ fun func() {
val <!UNUSED_VARIABLE!>a<!> = object {
val x = b
{
<!VAL_REASSIGNMENT!>b<!> = <!UNUSED_VALUE!>4<!>
<!VAL_REASSIGNMENT!>b<!> = 4
<!UNRESOLVED_REFERENCE!>$b<!> = 3
}
}
@@ -93,7 +93,7 @@ class MyTest() {
fun testInnerFunctions() {
var <!ASSIGNED_BUT_NEVER_ACCESSED_VARIABLE!>y<!> = 1
fun foo() {
y = <!UNUSED_VALUE!>1<!>
y = 1
}
var z = 1
fun bar() {
@@ -0,0 +1,21 @@
//KT-1191 Wrong detection of unused parameters
package kt1191
trait FunctionalList<T> {
val size: Int
val head: T
val tail: FunctionalList<T>
}
fun <erased T> FunctionalList<T>.plus(element: T) : FunctionalList<T> = object: FunctionalList<T> {
override val size: Int
get() = 1 + this@plus.size
override val tail: FunctionalList<T>
get() = this@plus
override val head: T
get() = element
}
fun foo(unused: Int) = object {
val a : Int get() = unused
}
@@ -0,0 +1,25 @@
//KT-1219 Incorrect 'unused value' error in closures
//+JDK
package kt1219
fun <T, R> Iterable<T>.fold(var r: R, op: (T, R) -> R) : R {
this.foreach { r = op(it, r) } //unused value here
return r
}
//KT-1301 Modification of local of outer function in a local function should not be marked as unused assignment
fun foo(){
var local = 0
fun bar(){
local = 1
}
bar()
System.out?.println(local)
}
fun <T> Iterable<T>.foreach(operation: (element: T) -> Unit) {
for (elem in this)
operation(elem)
}
@@ -23,7 +23,7 @@ fun foo() {
2
}
else {
z = <!UNUSED_VALUE!>34<!>
z = 34
}
}
val <!UNUSED_VARIABLE!>f<!>: ()-> Int = <!TYPE_MISMATCH!>r<!>
@@ -74,7 +74,7 @@ fun testCoercionToUnit() {
var <!ASSIGNED_BUT_NEVER_ACCESSED_VARIABLE!>x<!> = 43
val checkType = {
if (true) {
x = <!UNUSED_VALUE!>4<!>
x = 4
} else {
45
}
@@ -31,7 +31,7 @@ fun main(args: Array<String>) {
var m: MyNumber = MyNumber()
val <!UNUSED_VARIABLE!>a<!> = { (): MyNumber ->
<!UNUSED_CHANGED_VALUE!>m++<!>
m++
}
}