KT-5455 Need warning about redundant type cast
#KT-5455 Fixed
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
class G<T>
|
||||
|
||||
fun foo(p: <!UNRESOLVED_REFERENCE!>P<!>) {
|
||||
val v = <!DEBUG_INFO_ELEMENT_WITH_ERROR_TYPE!>p<!> <!USELESS_CAST!>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!>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<!>
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
open class A {
|
||||
fun foo() {}
|
||||
}
|
||||
class B : A()
|
||||
|
||||
fun test(b: B?) {
|
||||
(b as A).foo()
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
package
|
||||
|
||||
internal fun test(/*0*/ b: B?): kotlin.Unit
|
||||
|
||||
internal open class A {
|
||||
public constructor A()
|
||||
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
|
||||
internal final fun foo(): kotlin.Unit
|
||||
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
|
||||
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
|
||||
}
|
||||
|
||||
internal final class B : A {
|
||||
public constructor B()
|
||||
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
|
||||
internal final override /*1*/ /*fake_override*/ fun foo(): kotlin.Unit
|
||||
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
|
||||
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
|
||||
}
|
||||
@@ -11,7 +11,7 @@ fun f2(s: Number?) {
|
||||
}
|
||||
|
||||
fun f3(s: Number?) {
|
||||
if (s is Int && s as Int == 42);
|
||||
if (s is Int && s <!USELESS_CAST_STATIC_ASSERT_IS_FINE!>as<!> Int == 42);
|
||||
<!TYPE_MISMATCH!>s<!> : Int
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,28 @@
|
||||
//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 -1
|
||||
}
|
||||
|
||||
open class A {
|
||||
fun foo() {}
|
||||
}
|
||||
class B: A()
|
||||
|
||||
fun test(a: Any?) {
|
||||
if (a is B) {
|
||||
(a <!USELESS_CAST_STATIC_ASSERT_IS_FINE!>as<!> A).foo()
|
||||
}
|
||||
}
|
||||
|
||||
fun test1(a: B) {
|
||||
(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()
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
package
|
||||
|
||||
internal fun foo(/*0*/ o: kotlin.Any): kotlin.Int
|
||||
internal fun test(/*0*/ a: kotlin.Any?): kotlin.Unit
|
||||
internal fun test1(/*0*/ a: B): kotlin.Unit
|
||||
internal fun test2(/*0*/ b: B?): kotlin.Unit
|
||||
|
||||
internal open class A {
|
||||
public constructor A()
|
||||
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
|
||||
internal final fun foo(): kotlin.Unit
|
||||
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
|
||||
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
|
||||
}
|
||||
|
||||
internal final class B : A {
|
||||
public constructor B()
|
||||
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
|
||||
internal final override /*1*/ /*fake_override*/ fun foo(): kotlin.Unit
|
||||
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