[FIR] Fix substitution of Java arrays enhanced for warning

... w.r.t the variance of their type arguments.
Because `Object[]` is represented as `Array<Any>..Array<out Any>?`,
when we substitute, we can't just take the upper bound because it
changes the variance of the type agument.
Instead, we construct a flexible type and use both bounds, like with
collections with flexible mutability.

#KT-65246 Fixed
This commit is contained in:
Kirill Rakhman
2024-02-13 13:59:24 +01:00
committed by Space Team
parent 20f6b0cb0c
commit eae72eac54
4 changed files with 28 additions and 2 deletions
@@ -18,6 +18,8 @@ public class BaseClass {
public Foo explicitlyNullnessUnspecified(@NullnessUnspecified Foo x) { return null; }
public void withVararg(Object... p) { }
public static Foo foo() { return null; }
}
@@ -54,6 +56,8 @@ class Correct : IntermediateClass() {
override fun intermediateNotNull(): Foo {
return FOO
}
override fun withVararg(vararg p: Any) {}
}
class WrongReturnTypes : IntermediateClass() {
@@ -18,6 +18,8 @@ public class BaseClass {
public Foo explicitlyNullnessUnspecified(@NullnessUnspecified Foo x) { return null; }
public void withVararg(Object... p) { }
public static Foo foo() { return null; }
}
@@ -54,6 +56,8 @@ class Correct : IntermediateClass() {
override fun intermediateNotNull(): Foo {
return FOO
}
override fun withVararg(vararg p: Any) {}
}
class WrongReturnTypes : IntermediateClass() {
@@ -12,6 +12,7 @@ private val FOO: FOO.`<no name provided>`
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
@org.jspecify.annotations.Nullable public open fun mixed(/*0*/ x: Foo!): @org.jspecify.annotations.Nullable Foo!
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
public open fun withVararg(/*0*/ vararg p: kotlin.Any! /*kotlin.Array<(out) kotlin.Any!>!*/): kotlin.Unit
// Static members
public open fun foo(): Foo!
@@ -28,6 +29,7 @@ public final class Correct : IntermediateClass {
public open override /*1*/ fun intermediateNotNull(): Foo
public open override /*1*/ fun mixed(/*0*/ x: Foo): Foo?
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
public open override /*1*/ fun withVararg(/*0*/ vararg p: kotlin.Any /*kotlin.Array<out kotlin.Any>*/): kotlin.Unit
}
public interface Foo {
@@ -47,6 +49,7 @@ public open class IntermediateClass : BaseClass {
public open fun intermediateNotNull(): Foo!
@org.jspecify.annotations.Nullable public open override /*1*/ /*fake_override*/ fun mixed(/*0*/ x: Foo!): @org.jspecify.annotations.Nullable Foo!
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
public open override /*1*/ /*fake_override*/ fun withVararg(/*0*/ vararg p: kotlin.Any! /*kotlin.Array<(out) kotlin.Any!>!*/): kotlin.Unit
}
public final class WrongParameter : IntermediateClass {
@@ -60,6 +63,7 @@ public final class WrongParameter : IntermediateClass {
public open override /*1*/ /*fake_override*/ fun intermediateNotNull(): Foo!
public open override /*1*/ fun mixed(/*0*/ x: Foo?): Foo?
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
public open override /*1*/ /*fake_override*/ fun withVararg(/*0*/ vararg p: kotlin.Any! /*kotlin.Array<(out) kotlin.Any!>!*/): kotlin.Unit
}
public final class WrongReturnTypes : IntermediateClass {
@@ -73,5 +77,6 @@ public final class WrongReturnTypes : IntermediateClass {
public open override /*1*/ fun intermediateNotNull(): Foo?
@org.jspecify.annotations.Nullable public open override /*1*/ /*fake_override*/ fun mixed(/*0*/ x: Foo!): @org.jspecify.annotations.Nullable Foo!
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
public open override /*1*/ /*fake_override*/ fun withVararg(/*0*/ vararg p: kotlin.Any! /*kotlin.Array<(out) kotlin.Any!>!*/): kotlin.Unit
}