K2: Rework scopes for types with projection arguments for Out types

The only case when behavior is change is described at
 computeNonTrivialTypeArgumentForScopeSubstitutor

The idea is to avoid depending on the presence of @UnsafeVariance
and instead approximate captured types in covariant argument positions
before building substitution scopes

It's correct because for Captured(*) <: Supertype,
Out<Captured(*)> <: Out<Supertype> and when we've got @UnsafeVariance
value parameters at Out, it's ok to allow passing Supertype there.

^KT-57602 Fixed
^KT-54894 Fixed
This commit is contained in:
Denis.Zharkov
2023-03-24 17:21:03 +01:00
committed by Space Team
parent 1cd040fd6a
commit 55a58e54fe
25 changed files with 300 additions and 79 deletions
@@ -0,0 +1,13 @@
// ISSUE: KT-54764
data class Out<out T>(val prop: T)
fun foo(b: Out<*>) {
b.copy("") // error in K1, OK in K2
}
fun foo(a: Any) {
if (a is Out<*>) {
a.copy("")
}
}