Files
kotlin-fork/compiler/testData/diagnostics/tests/inference/tooEagerSmartcast.kt
T
Denis Zharkov d6b01f1007 NI: In subtyping do not intersect arguments for non-covariant types
It partially reverts 7898922066
because it's not obvious that it's a safe operation
for invariant/contravariant types.

Also, there's a necessary fix in prepareReceiverRegardingCaptureTypes
to make types order stable
Otherwise test bareTypesWithStarProjections becomes flaky.

Also, the changes in bareTypesWithStarProjections.kt are also expected
because the type of the expression `coneSymbol` after the second "if" is
FirVariableSymbol<*> & FirPropertySymbol & AbstractFirBasedSymbol<*>
thus we fix D in the call `coneSymbol.phasedFir()` to FirVariableSymbol<*>
because it's the first type in the list
(see the next line after the last changed in AbstractTypeChecker)
2020-01-14 17:35:24 +03:00

43 lines
986 B
Kotlin
Vendored

// SKIP_TXT
// !DIAGNOSTICS: -UNUSED_VARIABLE
// !LANGUAGE: +NewInference
interface OutBase<out E>
interface OutDerived<out F> : OutBase<F>
fun <X> OutBase<X>.myLast(): X = TODO()
fun <T> foo(x: OutBase<T>) {
if (x is OutDerived<*>) {
val l: T = x.myLast() // required T, found Cap(*). Only in NI
}
}
interface InvBase<E>
interface InvDerived<F> : InvBase<F>
fun <X> InvBase<X>.myLastInv(): X = TODO()
fun <T> fooInv(x: InvBase<T>) {
if (x is InvDerived<*>) {
val l: T = <!TYPE_MISMATCH!>x.<!TYPE_MISMATCH!>myLastInv()<!><!> // required T, found Cap(*). Only in NI
}
}
interface Base<E>
fun <Q> Base<Q>.foo(): Q = TODO()
fun <Q : CharSequence> Base<Q>.baz(): Q = TODO()
interface Derived<F : CharSequence> : Base<F>
fun Number.num() {}
fun main(b: Base<out Number>) {
b.foo().num()
if (b is Derived<*>) {
b.foo().<!DEBUG_INFO_UNRESOLVED_WITH_TARGET, UNRESOLVED_REFERENCE_WRONG_RECEIVER!>num<!>()
b.baz().length
}
}