Support warning about useless cast on safe cast

#KT-13348 Fixed
This commit is contained in:
Mikhail Zarechenskiy
2017-04-07 04:56:59 +03:00
parent 107879a78a
commit 7f287a4230
12 changed files with 56 additions and 23 deletions
@@ -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()
}
+2 -2
View File
@@ -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()
}