Support warning about useless cast on safe cast
#KT-13348 Fixed
This commit is contained in:
+2
-2
@@ -10,8 +10,8 @@ fun test() : Unit {
|
||||
checkSubtype<Int>(y <!USELESS_CAST!>as Int<!>)
|
||||
checkSubtype<Int?>(x as Int?)
|
||||
checkSubtype<Int?>(y as Int?)
|
||||
checkSubtype<Int?>(x <!USELESS_CAST!>as? Int<!>)
|
||||
checkSubtype<Int?>(y <!USELESS_CAST!>as? Int<!>)
|
||||
checkSubtype<Int?>(x as? Int)
|
||||
checkSubtype<Int?>(y as? Int)
|
||||
checkSubtype<Int?>(x as? Int?)
|
||||
checkSubtype<Int?>(y as? Int?)
|
||||
|
||||
|
||||
@@ -0,0 +1,22 @@
|
||||
// !DIAGNOSTICS: -UNUSED_PARAMETER, -UNUSED_VARIABLE
|
||||
|
||||
fun test(x: Int?) {
|
||||
val a1 = x <!USELESS_CAST!>as? Int<!>
|
||||
val a2 = x <!USELESS_CAST!>as? Int?<!>
|
||||
val a3 = x as? Number
|
||||
val a4 = x as? Number?
|
||||
val a5: Int? = x <!USELESS_CAST!>as? Int<!>
|
||||
val a6: Number? = x <!USELESS_CAST!>as? Int<!>
|
||||
val a7: Number? = 1 <!USELESS_CAST!>as? Number<!>
|
||||
|
||||
run { x <!USELESS_CAST!>as? Int<!> }
|
||||
run { x as? Number }
|
||||
|
||||
foo(x as? Number)
|
||||
|
||||
if (x is Int) {
|
||||
val b = x as? Int
|
||||
}
|
||||
}
|
||||
|
||||
fun foo(x: Number?) {}
|
||||
@@ -0,0 +1,4 @@
|
||||
package
|
||||
|
||||
public fun foo(/*0*/ x: kotlin.Number?): kotlin.Unit
|
||||
public fun test(/*0*/ x: kotlin.Int?): kotlin.Unit
|
||||
@@ -33,7 +33,7 @@ fun test() {
|
||||
if (x != null) {
|
||||
takeNotNull(dependOn(x) <!USELESS_ELVIS!>?: ""<!>)
|
||||
takeNotNull(dependOn(dependOn(x)) <!USELESS_ELVIS!>?: ""<!>)
|
||||
takeNotNull(dependOn(dependOn(x) <!USELESS_CAST!>as? String<!>) ?: "")
|
||||
takeNotNull(dependOn(dependOn(x) as? String) ?: "")
|
||||
}
|
||||
|
||||
takeNotNull(bar()!!)
|
||||
|
||||
@@ -16,7 +16,7 @@ fun String?.gav() {}
|
||||
fun bar(s: String?) {
|
||||
if (s != null) return
|
||||
<!DEBUG_INFO_CONSTANT!>s<!>.gav()
|
||||
<!DEBUG_INFO_CONSTANT!>s<!> as? String
|
||||
<!DEBUG_INFO_CONSTANT!>s<!> <!USELESS_CAST!>as? String<!>
|
||||
<!DEBUG_INFO_CONSTANT!>s<!> <!USELESS_CAST!>as String?<!>
|
||||
<!ALWAYS_NULL!>s<!> as String
|
||||
}
|
||||
@@ -7,7 +7,7 @@ fun <T> T?.let(f: (T) -> Unit) {
|
||||
}
|
||||
|
||||
fun test(your: Your?) {
|
||||
(your?.foo() as? Any)?.let {}
|
||||
(your?.foo() <!USELESS_CAST!>as? Any<!>)?.let {}
|
||||
// strange smart cast to 'Your' at this point
|
||||
your<!UNSAFE_CALL!>.<!>hashCode()
|
||||
}
|
||||
@@ -1,13 +1,13 @@
|
||||
// See also KT-10992: we should have no errors for all unsafe hashCode() calls
|
||||
|
||||
fun foo(arg: Any?) {
|
||||
val x = arg as? Any ?: return
|
||||
val x = arg <!USELESS_CAST!>as? Any<!> ?: return
|
||||
<!DEBUG_INFO_SMARTCAST!>arg<!>.hashCode()
|
||||
x.hashCode()
|
||||
}
|
||||
|
||||
fun bar(arg: Any?) {
|
||||
arg as? Any ?: return
|
||||
arg <!USELESS_CAST!>as? Any<!> ?: return
|
||||
<!DEBUG_INFO_SMARTCAST!>arg<!>.hashCode()
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user