Highlighting "as Foo" for useless casts in gray.

#KT-6070 fixed
This commit is contained in:
Evgeny Gerashchenko
2014-11-28 21:33:52 +03:00
parent 20ee59c1e5
commit a3fdce8131
34 changed files with 60 additions and 53 deletions
+6 -6
View File
@@ -5,12 +5,12 @@ fun test() : Unit {
x : Int?
y : Int
x as Int : Int
y <!USELESS_CAST!>as<!> Int : Int
x <!USELESS_CAST!>as<!> Int? : Int?
y <!USELESS_CAST_STATIC_ASSERT_IS_FINE!>as<!> Int? : Int?
y <!USELESS_CAST!>as Int<!> : Int
x <!USELESS_CAST!>as Int?<!> : Int?
y <!USELESS_CAST_STATIC_ASSERT_IS_FINE!>as Int?<!> : Int?
x as? Int : Int?
y <!USELESS_CAST!>as?<!> Int : Int?
x <!USELESS_CAST!>as?<!> Int? : Int?
y <!USELESS_CAST_STATIC_ASSERT_IS_FINE!>as?<!> Int? : Int?
y <!USELESS_CAST!>as? Int<!> : Int?
x <!USELESS_CAST!>as? Int?<!> : Int?
y <!USELESS_CAST_STATIC_ASSERT_IS_FINE!>as? Int?<!> : Int?
Unit
}
@@ -31,7 +31,7 @@ fun test() {
<!CONSTANT_EXPECTED_TYPE_MISMATCH!>1<!>: Float
1 <!CAST_NEVER_SUCCEEDS!>as<!> Byte
1 <!USELESS_CAST!>as<!> Int
1 <!USELESS_CAST!>as Int<!>
0xff <!CAST_NEVER_SUCCEEDS!>as<!> Long
1.1 <!CAST_NEVER_SUCCEEDS!>as<!> Int
@@ -45,7 +45,7 @@ fun cannotBe() {
<!VARIABLE_EXPECTED!>""<!> = "";
<!VARIABLE_EXPECTED!>foo()<!> = Unit;
(<!VARIABLE_EXPECTED!>i <!USELESS_CAST!>as<!> Int<!>) = 34
(<!VARIABLE_EXPECTED!>i <!USELESS_CAST!>as Int<!><!>) = 34
(<!VARIABLE_EXPECTED!>i is Int<!>) = false
<!VARIABLE_EXPECTED!>A()<!> = A()
<!VARIABLE_EXPECTED!>5<!> = 34
@@ -1,6 +1,6 @@
class G<T>
fun foo(p: <!UNRESOLVED_REFERENCE!>P<!>) {
val v = <!DEBUG_INFO_ELEMENT_WITH_ERROR_TYPE!>p<!> <!USELESS_CAST_STATIC_ASSERT_IS_FINE!>as<!> <!NO_TYPE_ARGUMENTS_ON_RHS!>G?<!>
val v = <!DEBUG_INFO_ELEMENT_WITH_ERROR_TYPE!>p<!> <!USELESS_CAST_STATIC_ASSERT_IS_FINE!>as <!NO_TYPE_ARGUMENTS_ON_RHS!>G?<!><!>
v!!: G<*>
}
@@ -1,6 +1,6 @@
class P
fun foo(p: P): Any {
val v = p <!USELESS_CAST_STATIC_ASSERT_IS_FINE!>as<!> <!UNRESOLVED_REFERENCE!>G<!>
val v = p <!USELESS_CAST_STATIC_ASSERT_IS_FINE!>as <!UNRESOLVED_REFERENCE!>G<!><!>
return <!DEBUG_INFO_ELEMENT_WITH_ERROR_TYPE!>v<!>
}
@@ -1,5 +1,5 @@
fun asCall() {
1 <!USELESS_CAST!>as<!> Int
1 <!USELESS_CAST!>as Int<!>
1 <!CAST_NEVER_SUCCEEDS!>as<!> Byte
1 <!CAST_NEVER_SUCCEEDS!>as<!> Short
1 <!CAST_NEVER_SUCCEEDS!>as<!> Long
@@ -12,7 +12,7 @@ fun asCall() {
1.0 <!CAST_NEVER_SUCCEEDS!>as<!> Short
1.0 <!CAST_NEVER_SUCCEEDS!>as<!> Long
1.0 <!CAST_NEVER_SUCCEEDS!>as<!> Char
1.0 <!USELESS_CAST!>as<!> Double
1.0 <!USELESS_CAST!>as Double<!>
1.0 <!CAST_NEVER_SUCCEEDS!>as<!> Float
1f <!CAST_NEVER_SUCCEEDS!>as<!> Int
@@ -21,11 +21,11 @@ fun asCall() {
1f <!CAST_NEVER_SUCCEEDS!>as<!> Long
1f <!CAST_NEVER_SUCCEEDS!>as<!> Char
1f <!CAST_NEVER_SUCCEEDS!>as<!> Double
1f <!USELESS_CAST!>as<!> Float
1f <!USELESS_CAST!>as Float<!>
}
fun asSafe() {
1 <!USELESS_CAST!>as?<!> Int
1 <!USELESS_CAST!>as? Int<!>
1 <!CAST_NEVER_SUCCEEDS!>as?<!> Byte
1 <!CAST_NEVER_SUCCEEDS!>as?<!> Short
1 <!CAST_NEVER_SUCCEEDS!>as?<!> Long
@@ -38,7 +38,7 @@ fun asSafe() {
1.0 <!CAST_NEVER_SUCCEEDS!>as?<!> Short
1.0 <!CAST_NEVER_SUCCEEDS!>as?<!> Long
1.0 <!CAST_NEVER_SUCCEEDS!>as?<!> Char
1.0 <!USELESS_CAST!>as?<!> Double
1.0 <!USELESS_CAST!>as? Double<!>
1.0 <!CAST_NEVER_SUCCEEDS!>as?<!> Float
1f <!CAST_NEVER_SUCCEEDS!>as?<!> Int
@@ -47,5 +47,5 @@ fun asSafe() {
1f <!CAST_NEVER_SUCCEEDS!>as?<!> Long
1f <!CAST_NEVER_SUCCEEDS!>as?<!> Char
1f <!CAST_NEVER_SUCCEEDS!>as?<!> Double
1f <!USELESS_CAST!>as?<!> Float
1f <!USELESS_CAST!>as? Float<!>
}
@@ -16,6 +16,6 @@ fun bar() {
x.foo()
X.foo()
(X : C).foo()
(X <!USELESS_CAST_STATIC_ASSERT_IS_FINE!>as<!> C).foo()
(X <!USELESS_CAST_STATIC_ASSERT_IS_FINE!>as C<!>).foo()
((if (1<2) X else Y) : C).foo()
}
@@ -11,7 +11,7 @@ fun f2(s: Number?) {
}
fun f3(s: Number?) {
if (s is Int && s <!USELESS_CAST_STATIC_ASSERT_IS_FINE!>as<!> Int == 42);
if (s is Int && s <!USELESS_CAST_STATIC_ASSERT_IS_FINE!>as Int<!> == 42);
<!TYPE_MISMATCH!>s<!> : Int
}
@@ -22,6 +22,6 @@ fun f4(a: Any) {
}
fun f5(a: String) {
a <!USELESS_CAST_STATIC_ASSERT_IS_FINE!>as<!> Any?
a <!USELESS_CAST_STATIC_ASSERT_IS_FINE!>as Any?<!>
a: String
}
@@ -1,7 +1,7 @@
//KT-5455 Need warning about redundant type cast
fun foo(o: Any): Int {
if (o is String) {
return (o <!USELESS_CAST_STATIC_ASSERT_IS_FINE!>as<!> String).length()
return (o <!USELESS_CAST_STATIC_ASSERT_IS_FINE!>as String<!>).length()
}
return -1
}
@@ -13,16 +13,16 @@ class B: A()
fun test(a: Any?) {
if (a is B) {
(a <!USELESS_CAST_STATIC_ASSERT_IS_FINE!>as<!> A).foo()
(a <!USELESS_CAST_STATIC_ASSERT_IS_FINE!>as A<!>).foo()
}
}
fun test1(a: B) {
(a <!USELESS_CAST_STATIC_ASSERT_IS_FINE!>as<!> A?)?.foo()
(a <!USELESS_CAST_STATIC_ASSERT_IS_FINE!>as A?<!>)?.foo()
}
fun test2(b: B?) {
if (b != null) {
(b <!USELESS_CAST_STATIC_ASSERT_IS_FINE!>as<!> A).foo()
(b <!USELESS_CAST_STATIC_ASSERT_IS_FINE!>as A<!>).foo()
}
}
@@ -1,5 +1,5 @@
suppress("REDUNDANT_NULLABLE")
class C {
suppress("UNNECESSARY_NOT_NULL_ASSERTION")
fun foo(): String?? = ""!! <!USELESS_CAST_STATIC_ASSERT_IS_FINE!>as<!> String??
fun foo(): String?? = ""!! <!USELESS_CAST_STATIC_ASSERT_IS_FINE!>as String??<!>
}
@@ -1,4 +1,4 @@
suppress("REDUNDANT_NULLABLE", "UNNECESSARY_NOT_NULL_ASSERTION")
class C {
fun foo(): String?? = ""!! <!USELESS_CAST_STATIC_ASSERT_IS_FINE!>as<!> String??
fun foo(): String?? = ""!! <!USELESS_CAST_STATIC_ASSERT_IS_FINE!>as String??<!>
}
@@ -1,6 +1,6 @@
class C {
suppress("REDUNDANT_NULLABLE", "UNNECESSARY_NOT_NULL_ASSERTION")
class object {
val foo: String?? = ""!! <!USELESS_CAST_STATIC_ASSERT_IS_FINE!>as<!> String??
val foo: String?? = ""!! <!USELESS_CAST_STATIC_ASSERT_IS_FINE!>as String??<!>
}
}
@@ -1,4 +1,4 @@
fun foo(): Any? {
[suppress("REDUNDANT_NULLABLE", "UNNECESSARY_NOT_NULL_ASSERTION")]
return ""!! <!USELESS_CAST_STATIC_ASSERT_IS_FINE!>as<!> String??
return ""!! <!USELESS_CAST_STATIC_ASSERT_IS_FINE!>as String??<!>
}
@@ -1,4 +1,4 @@
class C {
suppress("REDUNDANT_NULLABLE", "UNNECESSARY_NOT_NULL_ASSERTION")
fun foo(): String?? = ""!! <!USELESS_CAST_STATIC_ASSERT_IS_FINE!>as<!> String??
fun foo(): String?? = ""!! <!USELESS_CAST_STATIC_ASSERT_IS_FINE!>as String??<!>
}
@@ -1,4 +1,4 @@
suppress("REDUNDANT_NULLABLE", "UNNECESSARY_NOT_NULL_ASSERTION")
object C {
fun foo(): String?? = ""!! <!USELESS_CAST_STATIC_ASSERT_IS_FINE!>as<!> String??
fun foo(): String?? = ""!! <!USELESS_CAST_STATIC_ASSERT_IS_FINE!>as String??<!>
}
@@ -1,3 +1,3 @@
class C {
fun foo(suppress("REDUNDANT_NULLABLE", "UNNECESSARY_NOT_NULL_ASSERTION") p: String?? = ""!! <!USELESS_CAST_STATIC_ASSERT_IS_FINE!>as<!> String??) = p
fun foo(suppress("REDUNDANT_NULLABLE", "UNNECESSARY_NOT_NULL_ASSERTION") p: String?? = ""!! <!USELESS_CAST_STATIC_ASSERT_IS_FINE!>as String??<!>) = p
}
@@ -1,4 +1,4 @@
class C {
suppress("REDUNDANT_NULLABLE", "UNNECESSARY_NOT_NULL_ASSERTION")
val foo: String?? = ""!! <!USELESS_CAST_STATIC_ASSERT_IS_FINE!>as<!> String??
val foo: String?? = ""!! <!USELESS_CAST_STATIC_ASSERT_IS_FINE!>as String??<!>
}
@@ -1,5 +1,5 @@
class C {
val foo: String?
[suppress("REDUNDANT_NULLABLE", "UNNECESSARY_NOT_NULL_ASSERTION")]
get(): String?? = ""!! <!USELESS_CAST_STATIC_ASSERT_IS_FINE!>as<!> String??
get(): String?? = ""!! <!USELESS_CAST_STATIC_ASSERT_IS_FINE!>as String??<!>
}
@@ -1,4 +1,4 @@
suppress("REDUNDANT_NULLABLE")
class C {
fun foo(): String?? = null <!USELESS_CAST!>as<!> Nothing??
fun foo(): String?? = null <!USELESS_CAST!>as Nothing??<!>
}
@@ -1,6 +1,6 @@
class C {
suppress("REDUNDANT_NULLABLE")
class object {
val foo: String?? = null <!USELESS_CAST!>as<!> Nothing??
val foo: String?? = null <!USELESS_CAST!>as Nothing??<!>
}
}
@@ -1,4 +1,4 @@
fun foo(): Any? {
[suppress("REDUNDANT_NULLABLE")]
return null <!USELESS_CAST!>as<!> Nothing??
return null <!USELESS_CAST!>as Nothing??<!>
}
@@ -1,4 +1,4 @@
class C {
suppress("REDUNDANT_NULLABLE")
fun foo(): String?? = null <!USELESS_CAST!>as<!> Nothing??
fun foo(): String?? = null <!USELESS_CAST!>as Nothing??<!>
}
@@ -1,7 +1,7 @@
class C {
fun foo(): Any? {
[suppress("REDUNDANT_NULLABLE")]
val v: String?? = null <!USELESS_CAST!>as<!> Nothing??
val v: String?? = null <!USELESS_CAST!>as Nothing??<!>
return v
}
}
@@ -1,4 +1,4 @@
suppress("REDUNDANT_NULLABLE")
object C {
fun foo(): String?? = null <!USELESS_CAST!>as<!> Nothing??
fun foo(): String?? = null <!USELESS_CAST!>as Nothing??<!>
}
@@ -1,3 +1,3 @@
class C {
fun foo(suppress("REDUNDANT_NULLABLE") p: String?? = null <!USELESS_CAST!>as<!> Nothing??) = p
fun foo(suppress("REDUNDANT_NULLABLE") p: String?? = null <!USELESS_CAST!>as Nothing??<!>) = p
}
@@ -1,4 +1,4 @@
class C {
suppress("REDUNDANT_NULLABLE")
val foo: String?? = null <!USELESS_CAST!>as<!> Nothing?
val foo: String?? = null <!USELESS_CAST!>as Nothing?<!>
}
@@ -1,5 +1,5 @@
class C {
val foo: String?
[suppress("REDUNDANT_NULLABLE")]
get(): String?? = null <!USELESS_CAST!>as<!> Nothing??
get(): String?? = null <!USELESS_CAST!>as Nothing??<!>
}