Don't report useless cast in lambda if it has influence on return type
#KT-15161 Fixed #KT-12690 Fixed
This commit is contained in:
@@ -0,0 +1,52 @@
|
||||
// !DIAGNOSTICS: -UNUSED_PARAMETER
|
||||
|
||||
fun runWithoutReturn(r: () -> Unit) = r()
|
||||
|
||||
fun testRun() {
|
||||
run {
|
||||
1 <!USELESS_CAST!>as Any<!>
|
||||
1 as Any
|
||||
}
|
||||
|
||||
run<Any> {
|
||||
1 <!USELESS_CAST!>as Any<!>
|
||||
1 <!USELESS_CAST!>as Any<!>
|
||||
}
|
||||
|
||||
fun foo(): Int = 1
|
||||
|
||||
run {
|
||||
foo() as Any
|
||||
}
|
||||
|
||||
run {
|
||||
(if (true) 1 else 2) as Any
|
||||
}
|
||||
|
||||
run<Int?> {
|
||||
1 <!USELESS_CAST!>as Int<!>
|
||||
1 <!USELESS_CAST!>as Int<!>
|
||||
}
|
||||
|
||||
runWithoutReturn {
|
||||
1 <!USELESS_CAST!>as Any<!>
|
||||
1 <!USELESS_CAST!>as Any<!>
|
||||
}
|
||||
}
|
||||
|
||||
fun testReturn(): Number {
|
||||
run { 1 as Number }
|
||||
return run { 1 <!USELESS_CAST!>as Number<!> }
|
||||
}
|
||||
|
||||
fun <T> testDependent() {
|
||||
listOf(1).map {
|
||||
it <!USELESS_CAST!>as Any<!>
|
||||
it as Any
|
||||
}
|
||||
|
||||
listOf<T>().map { it as Any? }
|
||||
}
|
||||
|
||||
fun <T> listOf(vararg elements: T): List<T> = TODO()
|
||||
fun <T, R> Iterable<T>.map(transform: (T) -> R): List<R> = TODO()
|
||||
@@ -0,0 +1,8 @@
|
||||
package
|
||||
|
||||
public fun </*0*/ T> listOf(/*0*/ vararg elements: T /*kotlin.Array<out T>*/): kotlin.collections.List<T>
|
||||
public fun runWithoutReturn(/*0*/ r: () -> kotlin.Unit): kotlin.Unit
|
||||
public fun </*0*/ T> testDependent(): kotlin.Unit
|
||||
public fun testReturn(): kotlin.Number
|
||||
public fun testRun(): kotlin.Unit
|
||||
public fun </*0*/ T, /*1*/ R> kotlin.collections.Iterable<T>.map(/*0*/ transform: (T) -> R): kotlin.collections.List<R>
|
||||
@@ -0,0 +1,6 @@
|
||||
class Array<E>(e: E) {
|
||||
val k = Array(1) {
|
||||
1 <!USELESS_CAST!>as Any<!>
|
||||
e as Any?
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
package
|
||||
|
||||
public final class Array</*0*/ E> {
|
||||
public constructor Array</*0*/ E>(/*0*/ e: E)
|
||||
public final val k: kotlin.Array<kotlin.Any?>
|
||||
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
|
||||
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
|
||||
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
|
||||
}
|
||||
Reference in New Issue
Block a user