FIR checker: warn useless as and is

This commit is contained in:
Jinseong Jeon
2021-04-28 22:32:51 -07:00
committed by TeamCityServer
parent 19d939c36e
commit e2dc21da90
141 changed files with 417 additions and 543 deletions
@@ -25,8 +25,8 @@ fun testRun() {
}
run<Int?> {
1 as Int
1 as Int
1 <!USELESS_CAST!>as Int<!>
1 <!USELESS_CAST!>as Int<!>
}
runWithoutReturn {
@@ -4,7 +4,7 @@ fun test() {
val a = 1 as Any?
val b: Number = 1 as Number
val c = null as String?
val d: Number = 1 as Int
val d: Number = 1 <!USELESS_CAST!>as Int<!>
}
val c1 get() = 1 as Number
@@ -14,4 +14,4 @@ val d: Number
get() {
1 as Number
return 1 as Number
}
}
@@ -18,9 +18,9 @@ public class Foo {
fun test() {
Foo.create() as Foo
Foo.createN() as Foo
Foo.createNN() as Foo
Foo.createNN() <!USELESS_CAST!>as Foo<!>
Foo.create() as Foo?
Foo.createN() as Foo?
Foo.create() <!USELESS_CAST!>as Foo?<!>
Foo.createN() <!USELESS_CAST!>as Foo?<!>
Foo.createNN() as Foo?
}
}
@@ -1,5 +0,0 @@
open class Base<A>
class Some: Base<Int>()
// a is Some => a is Base<Int>
fun f(a: Some) = a is Base<Int>
@@ -1,3 +1,4 @@
// FIR_IDENTICAL
open class Base<A>
class Some: Base<Int>()
@@ -1,8 +0,0 @@
open class A
open class B: A()
open class Base<in T>
class SubBase: Base<A>()
// f is SubBase => f is Base<A> => (Base<Contravariant T>, B <: A) f is Base<B>
fun test(f: SubBase) = f is Base<B>
@@ -1,3 +1,4 @@
// FIR_IDENTICAL
open class A
open class B: A()
@@ -1,8 +0,0 @@
open class A
open class B: A()
open class Base<out T>
class SubBase: Base<B>()
// f is SubBase => (SubBase <: Base<B>) f is Base<B> => (B <: A, Base<Covariant T> => SubBase <: Base<A>) f is Base<A>
fun test(f: SubBase) = f is Base<A>
@@ -1,3 +1,4 @@
// FIR_IDENTICAL
open class A
open class B: A()
@@ -1 +0,0 @@
fun f(a: MutableList<out Number>) = a is MutableList<out Any>
@@ -1 +1,2 @@
// FIR_IDENTICAL
fun f(a: MutableList<out Number>) = <!USELESS_IS_CHECK!>a is MutableList<out Any><!>
@@ -1 +0,0 @@
fun f(a: MutableList<String>) = a is MutableList<out CharSequence>
@@ -1 +1,2 @@
// FIR_IDENTICAL
fun f(a: MutableList<String>) = <!USELESS_IS_CHECK!>a is MutableList<out CharSequence><!>
@@ -1 +0,0 @@
fun f(a: List<Number>) = a is List<Any>
@@ -1 +1,2 @@
// FIR_IDENTICAL
fun f(a: List<Number>) = <!USELESS_IS_CHECK!>a is List<Any><!>
@@ -1 +0,0 @@
fun <T> testing(a: T) = a is T
@@ -1 +1,2 @@
// FIR_IDENTICAL
fun <T> testing(a: T) = <!USELESS_IS_CHECK!>a is T<!>
@@ -1,14 +1,14 @@
fun <T, S : T> test(x: T?, y: S, z: T) {
x is T
x is T?
<!USELESS_IS_CHECK!>x is T?<!>
y is T
y is S
y is T?
y is S?
<!USELESS_IS_CHECK!>y is T<!>
<!USELESS_IS_CHECK!>y is S<!>
<!USELESS_IS_CHECK!>y is T?<!>
<!USELESS_IS_CHECK!>y is S?<!>
z is T
z is T?
<!USELESS_IS_CHECK!>z is T<!>
<!USELESS_IS_CHECK!>z is T?<!>
null as T
null as T?
@@ -22,6 +22,6 @@ inline fun <reified T> test(x: T?) {
}
fun <T> foo(x: List<T>, y: List<T>?) {
x is List<T>
<!USELESS_IS_CHECK!>x is List<T><!>
y is List<T>
}
}
@@ -2,15 +2,15 @@
// !DIAGNOSTICS: -UNUSED_PARAMETER, -UNUSED_VARIABLE
fun test(x: Int?) {
val a1 = x as? Int
val a2 = x as? 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 as? Int
val a6: Number? = x as? Int
val a5: Int? = x <!USELESS_CAST!>as? Int<!>
val a6: Number? = x <!USELESS_CAST!>as? Int<!>
val a7: Number? = 1 as? Number
run { x as? Int }
run { x <!USELESS_CAST!>as? Int<!> }
run { x as? Number }
foo(x as? Number)
@@ -22,17 +22,17 @@ public class JavaClass {
// FILE: test.kt
fun <T, S: Any> test(x1: T, x2: T?, y1: S, y2: S?) {
x1 is T?
x2 is T?
y1 is S?
y2 is S?
<!USELESS_IS_CHECK!>x1 is T?<!>
<!USELESS_IS_CHECK!>x2 is T?<!>
<!USELESS_IS_CHECK!>y1 is S?<!>
<!USELESS_IS_CHECK!>y2 is S?<!>
val f1 = JavaClass.foo()
f1 is Int?
<!USELESS_IS_CHECK!>f1 is Int?<!>
val f2 = JavaClass.fooN()
f2 is Int?
<!USELESS_IS_CHECK!>f2 is Int?<!>
val f3 = JavaClass.fooNN()
f3 is Int?
<!USELESS_IS_CHECK!>f3 is Int?<!>
}
+4 -4
View File
@@ -1,5 +1,5 @@
fun asCall() {
1 as Int
1 <!USELESS_CAST!>as Int<!>
1 as Byte
1 as Short
1 as Long
@@ -12,7 +12,7 @@ fun asCall() {
1.0 as Short
1.0 as Long
1.0 as Char
1.0 as Double
1.0 <!USELESS_CAST!>as Double<!>
1.0 as Float
1f as Int
@@ -21,7 +21,7 @@ fun asCall() {
1f as Long
1f as Char
1f as Double
1f as Float
1f <!USELESS_CAST!>as Float<!>
}
fun asSafe() {
@@ -48,4 +48,4 @@ fun asSafe() {
1f as? Char
1f as? Double
1f as? Float
}
}