fab6cec93a
This makes it more consistent and fixes some overlooked corner cases. Also it was decided on the last equality applicability DM (KT-62646) that we'd like `is`/`!is`/`as`/`as?` to work similarly to `===`/`!==`. Also note that it now gives a clearer explaination of why some corner cases work the way they do. For example, `FirPsiDiagnosticTestGenerated.testLambdaInLhsOfTypeOperatorCall` yields `UNCHECKED_CAST` instead of `CAST_NEVER_SUCCEEDS`, because `toTypeInfo()` replaces all type arguments with star projections, even when the argument is not a type parameter. This is because it has been desided to work this way in KT-57779. In `FirPsiOldFrontendDiagnosticsTestGenerated..NeverSucceeds#testNoGenericsRelated` the diagnostic is introduced, because `t2 as FC1` and `FC1` is a final class with no `T5` supertype. `UNCHECKED_CAST` in `FirPsiOldFrontendDiagnosticsTestGenerated.testSmartCast` disappeared, because previously we didn't take smartcasts into account. Note that `FirPsiOldFrontendDiagnosticsTestGenerated.testMappedSubtypes` is a false positive. It appears because `isSubtypeOf()` doesn't take into account platform types in supertypes of the given types (doesn't map them).
43 lines
1009 B
Kotlin
Vendored
43 lines
1009 B
Kotlin
Vendored
fun <T, S : T> test(x: T?, y: S, z: T) {
|
|
x is <!CANNOT_CHECK_FOR_ERASED!>T<!>
|
|
<!USELESS_IS_CHECK!>x is T?<!>
|
|
|
|
<!USELESS_IS_CHECK!>y is T<!>
|
|
<!USELESS_IS_CHECK!>y is S<!>
|
|
<!USELESS_IS_CHECK!>y is T?<!>
|
|
<!USELESS_IS_CHECK!>y is S?<!>
|
|
|
|
<!USELESS_IS_CHECK!>z is T<!>
|
|
<!USELESS_IS_CHECK!>z is T?<!>
|
|
|
|
null <!UNCHECKED_CAST!>as T<!>
|
|
null as T?
|
|
null <!UNCHECKED_CAST!>as S<!>
|
|
}
|
|
|
|
class Box<T>
|
|
|
|
inline fun <reified T> test(x: T?, a: Any) {
|
|
x is T
|
|
null as T
|
|
null as T?
|
|
|
|
a is T
|
|
a as T
|
|
|
|
a is <!CANNOT_CHECK_FOR_ERASED!>Box<T><!>
|
|
a is <!CANNOT_CHECK_FOR_ERASED!>Array<T><!>
|
|
a <!UNCHECKED_CAST!>as Box<T><!>
|
|
a <!CAST_NEVER_SUCCEEDS!>as<!> Array<T>
|
|
|
|
a is <!CANNOT_CHECK_FOR_ERASED!>Box<List<T>><!>
|
|
a is <!CANNOT_CHECK_FOR_ERASED!>Array<List<T>><!>
|
|
a <!UNCHECKED_CAST!>as Box<List<T>><!>
|
|
a <!UNCHECKED_CAST!>as Array<List<T>><!>
|
|
}
|
|
|
|
fun <T> foo(x: List<T>, y: List<T>?) {
|
|
<!USELESS_IS_CHECK!>x is List<T><!>
|
|
y is List<T>
|
|
}
|