K2: repeat K1 representation for flexible type parameters

This commit changes the behavior of KT-59138 effectively declining it in 2.0.
However, we plan to implement KT-59138 behavior under a feature
flag in 2.0 (see KT-66447), and switch this feature on version 2.x.

Also, this commit implements the LC resolution about postponing
KT-57014 change. We don't have KT-57014 described behavior in 2.0 anymore.
However, we plan to implement a deprecation warning here, see KT-65578.

After this commit, 6 diagnostic tests become incorrectly broken:
- 5 tests from PurelyImplementedCollection group
- a test platformTypes/nullableTypeArgument.kt

This commit also breaks currently fixed-in-k2 KT-50134
(it is fixed again in the following commits),
as well as KT-58933 (it will remain not fixed till we enable KT-59138
behavior again).

#KT-65596 In Progress
#KT-57014 In Progress
#KT-58933 Submitted
This commit is contained in:
Denis.Zharkov
2024-02-06 15:33:03 +01:00
committed by Space Team
parent 7fd46f1450
commit 81414d758d
160 changed files with 343 additions and 479 deletions
@@ -7,13 +7,13 @@ B2:
[IntersectionOverride]: public open override fun remove(p0: R|@EnhancedNullability kotlin/Int|): R|kotlin/Boolean| from Use site scope of /B2 [id: 0]
[SubstitutionOverride(DeclarationSite)]: public open override fun remove(p0: R|@EnhancedNullability kotlin/Int|): R|kotlin/Boolean| from Substitution scope for [Java enhancement scope for java/util/ArrayList] for type B2 [id: 1]
[Enhancement]: public open fun remove(p0: R|@EnhancedNullability E|): R|kotlin/Boolean| from Java enhancement scope for java/util/ArrayList [id: 2]
[SubstitutionOverride(DeclarationSite)]: public open override fun remove(p0: R|ft<E & Any, E?>|): R|kotlin/Boolean| from Substitution scope for [Java enhancement scope for java/util/AbstractList] for type java/util/ArrayList<E> [id: 3]
[IntersectionOverride]: public open override fun remove(p0: R|ft<E & Any, E?>|): R|kotlin/Boolean| from Java enhancement scope for java/util/AbstractList [id: 4]
[SubstitutionOverride(DeclarationSite)]: public open override fun remove(p0: R|ft<E & Any, E?>|): R|kotlin/Boolean| from Substitution scope for [Java enhancement scope for java/util/AbstractCollection] for type java/util/AbstractList<E> [id: 5]
[Enhancement]: public open fun remove(p0: R|ft<E & Any, E?>|): R|kotlin/Boolean| from Java enhancement scope for java/util/AbstractCollection [id: 6]
[SubstitutionOverride(DeclarationSite)]: public abstract override fun remove(element: R|ft<E & Any, E?>|): R|kotlin/Boolean| from Substitution scope for [Use site scope of kotlin/collections/MutableCollection] for type java/util/AbstractCollection<E> [id: 7]
[SubstitutionOverride(DeclarationSite)]: public open override fun remove(p0: R|E!|): R|kotlin/Boolean| from Substitution scope for [Java enhancement scope for java/util/AbstractList] for type java/util/ArrayList<E> [id: 3]
[IntersectionOverride]: public open override fun remove(p0: R|E!|): R|kotlin/Boolean| from Java enhancement scope for java/util/AbstractList [id: 4]
[SubstitutionOverride(DeclarationSite)]: public open override fun remove(p0: R|E!|): R|kotlin/Boolean| from Substitution scope for [Java enhancement scope for java/util/AbstractCollection] for type java/util/AbstractList<E> [id: 5]
[Enhancement]: public open fun remove(p0: R|E!|): R|kotlin/Boolean| from Java enhancement scope for java/util/AbstractCollection [id: 6]
[SubstitutionOverride(DeclarationSite)]: public abstract override fun remove(element: R|E!|): R|kotlin/Boolean| from Substitution scope for [Use site scope of kotlin/collections/MutableCollection] for type java/util/AbstractCollection<E> [id: 7]
[Library]: public abstract fun remove(element: R|E|): R|kotlin/Boolean| from Use site scope of kotlin/collections/MutableCollection [id: 8]
[SubstitutionOverride(DeclarationSite)]: public abstract override fun remove(element: R|ft<E & Any, E?>|): R|kotlin/Boolean| from Substitution scope for [Use site scope of kotlin/collections/MutableList] for type java/util/AbstractList<E> [id: 9]
[SubstitutionOverride(DeclarationSite)]: public abstract override fun remove(element: R|E!|): R|kotlin/Boolean| from Substitution scope for [Use site scope of kotlin/collections/MutableList] for type java/util/AbstractList<E> [id: 9]
[Library]: public abstract fun remove(element: R|E|): R|kotlin/Boolean| from Use site scope of kotlin/collections/MutableList [id: 10]
[SubstitutionOverride(DeclarationSite)]: public abstract override fun remove(element: R|E|): R|kotlin/Boolean| from Substitution scope for [Use site scope of kotlin/collections/MutableCollection] for type kotlin/collections/MutableList<E> [id: 11]
[Library]: public abstract fun remove(element: R|E|): R|kotlin/Boolean| from Use site scope of kotlin/collections/MutableCollection [id: 8]
@@ -1,21 +0,0 @@
// ISSUE: KT-59138
// SKIP_TXT
// FILE: JavaClass.java
public class JavaClass {
public static <K> K simpleId(K k) { // fun <K> simpleId(k: K & Any..K?): K & Any..K? =
return k;
}
}
// FILE: main.kt
fun takeN(n: Number?): Int = 1
fun bar(n: Number?) {
fun takeN(n: Number): String = ""
// in K1, it was resolved to nullable takeN
// in K2, it would be resolved to not-nullable and may fail with NPE
takeN(JavaClass.simpleId(n)).<!UNRESOLVED_REFERENCE!>div<!>(1)
takeN(JavaClass.simpleId(n)).length
}
@@ -1,3 +1,4 @@
// FIR_IDENTICAL
// ISSUE: KT-59138
// SKIP_TXT
// FILE: JavaClass.java
@@ -5,8 +5,8 @@ A:
[Library]: public abstract fun removeAt(index: R|kotlin/Int|): R|E| from Use site scope of kotlin/collections/AbstractMutableList [id: 2]
[SubstitutionOverride(DeclarationSite)]: public abstract override fun removeAt(index: R|kotlin/Int|): R|E| from Substitution scope for [Use site scope of kotlin/collections/MutableList] for type kotlin/collections/AbstractMutableList<E> [id: 3]
[Library]: public abstract fun removeAt(index: R|kotlin/Int|): R|E| from Use site scope of kotlin/collections/MutableList [id: 4]
[SubstitutionOverride(DeclarationSite)]: public open override operator fun removeAt(p0: R|kotlin/Int|): R|ft<E & Any, E?>| from Substitution scope for [Java enhancement scope for java/util/AbstractList] for type kotlin/collections/AbstractMutableList<E> [id: 5]
[Enhancement]: public open operator fun removeAt(p0: R|kotlin/Int|): R|ft<E & Any, E?>| from Java enhancement scope for java/util/AbstractList [id: 6]
[SubstitutionOverride(DeclarationSite)]: public abstract override fun removeAt(index: R|kotlin/Int|): R|ft<E & Any, E?>| from Substitution scope for [Use site scope of kotlin/collections/MutableList] for type java/util/AbstractList<E> [id: 7]
[SubstitutionOverride(DeclarationSite)]: public open override operator fun removeAt(p0: R|kotlin/Int|): R|E!| from Substitution scope for [Java enhancement scope for java/util/AbstractList] for type kotlin/collections/AbstractMutableList<E> [id: 5]
[Enhancement]: public open operator fun removeAt(p0: R|kotlin/Int|): R|E!| from Java enhancement scope for java/util/AbstractList [id: 6]
[SubstitutionOverride(DeclarationSite)]: public abstract override fun removeAt(index: R|kotlin/Int|): R|E!| from Substitution scope for [Use site scope of kotlin/collections/MutableList] for type java/util/AbstractList<E> [id: 7]
[Library]: public abstract fun removeAt(index: R|kotlin/Int|): R|E| from Use site scope of kotlin/collections/MutableList [id: 4]
@@ -2,6 +2,6 @@ D:
[SubstitutionOverride(DeclarationSite)]: public open override fun foo(x: R|kotlin/Int!|): R|kotlin/String!| from Use site scope of /D [id: 0]
[SubstitutionOverride(DeclarationSite)]: public open override fun foo(x: R|kotlin/Int!|): R|kotlin/String!| from Use site scope of /C [id: 0]
[SubstitutionOverride(DeclarationSite)]: public open override fun foo(x: R|kotlin/Int!|): R|kotlin/String!| from Substitution scope for [Java enhancement scope for /A] for type C [id: 0]
[Enhancement]: public open fun foo(x: R|kotlin/Int!|): R|ft<T & Any, T?>| from Java enhancement scope for /A [id: 1]
[Enhancement]: public open fun foo(x: R|kotlin/Int!|): R|T!| from Java enhancement scope for /A [id: 1]
[Source]: public open fun foo(x: R|kotlin/Int|): R|kotlin/String| from Use site scope of /D [id: 0]
[Source]: public open fun foo(x: R|kotlin/Int|): R|kotlin/String| from Use site scope of /B [id: 0]
@@ -2,6 +2,6 @@ D:
[SubstitutionOverride(DeclarationSite)]: public open override fun foo(x: R|kotlin/Int!|): R|kotlin/String!| from Use site scope of /D [id: 0]
[SubstitutionOverride(DeclarationSite)]: public open override fun foo(x: R|kotlin/Int!|): R|kotlin/String!| from Java enhancement scope for /C [id: 0]
[SubstitutionOverride(DeclarationSite)]: public open override fun foo(x: R|kotlin/Int!|): R|kotlin/String!| from Substitution scope for [Java enhancement scope for /A] for type C [id: 0]
[Enhancement]: public open fun foo(x: R|ft<T & Any, T?>|): R|kotlin/String!| from Java enhancement scope for /A [id: 1]
[Enhancement]: public open fun foo(x: R|T!|): R|kotlin/String!| from Java enhancement scope for /A [id: 1]
[Source]: public open fun foo(x: R|kotlin/Int|): R|kotlin/String| from Use site scope of /D [id: 0]
[Source]: public open fun foo(x: R|kotlin/Int|): R|kotlin/String| from Use site scope of /B [id: 0]
@@ -2,6 +2,6 @@ D:
[SubstitutionOverride(DeclarationSite)]: public open override fun foo(x: R|kotlin/Int!|): R|kotlin/String!| from Use site scope of /D [id: 0]
[SubstitutionOverride(DeclarationSite)]: public open override fun foo(x: R|kotlin/Int!|): R|kotlin/String!| from Use site scope of /C [id: 0]
[SubstitutionOverride(DeclarationSite)]: public open override fun foo(x: R|kotlin/Int!|): R|kotlin/String!| from Substitution scope for [Java enhancement scope for /A] for type C [id: 0]
[Enhancement]: public open fun foo(x: R|ft<T & Any, T?>|): R|kotlin/String!| from Java enhancement scope for /A [id: 1]
[Enhancement]: public open fun foo(x: R|T!|): R|kotlin/String!| from Java enhancement scope for /A [id: 1]
[Source]: public open fun foo(x: R|kotlin/Int|): R|kotlin/String| from Use site scope of /D [id: 0]
[Source]: public open fun foo(x: R|kotlin/Int|): R|kotlin/String| from Use site scope of /B [id: 0]
@@ -2,7 +2,7 @@ E:
[IntersectionOverride]: public? open override fun foo(x: R|kotlin/Int|): R|kotlin/String| from Use site scope of /E [id: 0]
[SubstitutionOverride(DeclarationSite)]: public open override fun foo(x: R|kotlin/Int!|): R|kotlin/String!| from Use site scope of /C [id: 1]
[SubstitutionOverride(DeclarationSite)]: public open override fun foo(x: R|kotlin/Int!|): R|kotlin/String!| from Substitution scope for [Java enhancement scope for /A] for type C [id: 1]
[Enhancement]: public open fun foo(x: R|ft<T & Any, T?>|): R|kotlin/String!| from Java enhancement scope for /A [id: 2]
[Enhancement]: public open fun foo(x: R|T!|): R|kotlin/String!| from Java enhancement scope for /A [id: 2]
[SubstitutionOverride(DeclarationSite)]: public open override fun foo(x: R|kotlin/Int|): R|kotlin/String| from Use site scope of /D [id: 3]
[SubstitutionOverride(DeclarationSite)]: public open override fun foo(x: R|kotlin/Int|): R|kotlin/String| from Substitution scope for [Use site scope of /B] for type D [id: 3]
[Source]: public open fun foo(x: R|T|): R|kotlin/String| from Use site scope of /B [id: 4]
@@ -23,7 +23,7 @@ fun <V> SLRUMap<V>.getOrPut(value: V, l: List<V>) {
takeE(<!ARGUMENT_TYPE_MISMATCH!>value<!>)
takeEList(<!ARGUMENT_TYPE_MISMATCH!>l<!>)
takeE(id(value))
takeE(<!ARGUMENT_TYPE_MISMATCH!>id(value)<!>)
if (value != null) {
takeV(value)
@@ -5,3 +5,5 @@
/main.kt:(133,138): error: Argument type mismatch: actual type is 'V', but 'E & Any' was expected.
/main.kt:(154,155): error: Argument type mismatch: actual type is 'kotlin.collections.List<V>', but 'kotlin.collections.(Mutable)List<@NotNull() E & Any>' was expected.
/main.kt:(167,176): error: Argument type mismatch: actual type is 'V!', but 'E & Any' was expected.
@@ -24,7 +24,7 @@ fun <V> SLRUMap<V>.getOrPut(value: V, l: List<V>) {
takeE(<!ARGUMENT_TYPE_MISMATCH!>value<!>)
takeEList(<!ARGUMENT_TYPE_MISMATCH!>l<!>)
takeE(id(value))
takeE(<!ARGUMENT_TYPE_MISMATCH!>id(value)<!>)
if (value != null) {
takeV(value)