[FIR] Resolve array literal with non-primitive-array expected type as arrayOf call

This lets us properly complete the call which fixes some issues with
false-positive type mismatches.
This change doesn't apply to array literals in annotation calls yet
because they are resolved as context-dependent.
This will be adapted in a following commit.

#KT-59581
This commit is contained in:
Kirill Rakhman
2023-07-04 14:27:43 +02:00
committed by Space Team
parent 4ead02271b
commit ff6b3350ae
16 changed files with 92 additions and 118 deletions
@@ -6,7 +6,7 @@ fun test() {
val b: Array<Int> = []
val c = [1, 2]
val d: Array<Int> = [1, 2]
val e: Array<String> = <!INITIALIZER_TYPE_MISMATCH!>[1]<!>
val e: Array<String> = <!TYPE_MISMATCH, TYPE_MISMATCH!>[1]<!>
val f: IntArray = [1, 2]
val g = [f]
@@ -1,13 +1,16 @@
import kotlin.reflect.KClass
annotation class Foo(
val a: Array<String> = ["/"],
val b: Array<String> = [],
val c: Array<String> = ["1", "2"]
val c: Array<String> = ["1", "2"],
val d: Array<KClass<*>> = [Int::class, Array<Int>::class],
)
annotation class Bar(
val a: Array<String> = <!INITIALIZER_TYPE_MISMATCH!>[' ']<!>,
val a: Array<String> = <!TYPE_MISMATCH, TYPE_MISMATCH!>[' ']<!>,
val b: Array<String> = ["", <!EMPTY_CHARACTER_LITERAL!>''<!>],
val c: Array<String> = <!INITIALIZER_TYPE_MISMATCH!>[1]<!>
val c: Array<String> = <!TYPE_MISMATCH, TYPE_MISMATCH!>[1]<!>
)
annotation class Base(
@@ -19,5 +22,5 @@ annotation class Base(
annotation class Err(
val a: IntArray = <!INITIALIZER_TYPE_MISMATCH!>[1L]<!>,
val b: Array<String> = <!INITIALIZER_TYPE_MISMATCH!>[1]<!>
val b: Array<String> = <!TYPE_MISMATCH, TYPE_MISMATCH!>[1]<!>
)
@@ -1,7 +1,10 @@
import kotlin.reflect.KClass
annotation class Foo(
val a: Array<String> = ["/"],
val b: Array<String> = [],
val c: Array<String> = ["1", "2"]
val c: Array<String> = ["1", "2"],
val d: Array<KClass<*>> = [Int::class, Array<Int>::class],
)
annotation class Bar(
@@ -31,10 +31,11 @@ public final annotation class Err : kotlin.Annotation {
}
public final annotation class Foo : kotlin.Annotation {
public constructor Foo(/*0*/ a: kotlin.Array<kotlin.String> = ..., /*1*/ b: kotlin.Array<kotlin.String> = ..., /*2*/ c: kotlin.Array<kotlin.String> = ...)
public constructor Foo(/*0*/ a: kotlin.Array<kotlin.String> = ..., /*1*/ b: kotlin.Array<kotlin.String> = ..., /*2*/ c: kotlin.Array<kotlin.String> = ..., /*3*/ d: kotlin.Array<kotlin.reflect.KClass<*>> = ...)
public final val a: kotlin.Array<kotlin.String>
public final val b: kotlin.Array<kotlin.String>
public final val c: kotlin.Array<kotlin.String>
public final val d: kotlin.Array<kotlin.reflect.KClass<*>>
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String