Files
Nikolay Lunyak fab6cec93a [FIR] Utilize equality compatibility logic for cast checks
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).
2024-03-08 15:37:44 +00:00

54 lines
970 B
Kotlin
Vendored

fun <E> foo(x: Any, y: Any) : Any {
class C
// without E?
if (x is <!CANNOT_CHECK_FOR_ERASED!>C<!>) {
return x
}
if (1 == 2) {
x <!UNCHECKED_CAST!>as C<!>
}
if (2 == 3) {
x <!UNCHECKED_CAST!>as? C<!>
}
class Outer<F> {
inner class Inner
}
// bare type
if (y is <!NO_TYPE_ARGUMENTS_ON_RHS!>Outer<!>) {
return y
}
if (y is <!CANNOT_CHECK_FOR_ERASED!>Outer<*><!>) {
return y
}
if (y is <!NO_TYPE_ARGUMENTS_ON_RHS!>Outer.Inner<!>) {
return y
}
if (y is <!CANNOT_CHECK_FOR_ERASED!>Outer<*>.Inner<!>) {
return y
}
y <!UNCHECKED_CAST!>as Outer<*><!>
y as <!NO_TYPE_ARGUMENTS_ON_RHS!>Outer<!>
y <!CAST_NEVER_SUCCEEDS!>as<!> Outer<*>.Inner
y as <!NO_TYPE_ARGUMENTS_ON_RHS!>Outer.Inner<!>
return C()
}
fun noTypeParameters(x: Any) : Any {
class C
if(x is C) {
return x
}
return C()
}