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
@@ -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)
}