[FIR] Resolve array literal argument for non-primitive-array parameter as arrayOf call in annotation calls

This allows us to properly complete array literals arguments of
annotation calls fixing several false-negative type mismatch errors
as well as enabling the inference of generic type arguments.

#KT-59581 Fixed
#KT-58883 Fixed
This commit is contained in:
Kirill Rakhman
2023-07-18 12:01:05 +02:00
committed by Space Team
parent e69b695efd
commit 97024d9ccb
14 changed files with 145 additions and 34 deletions
@@ -6,7 +6,7 @@ fun test1() {}
@Foo([], [], [])
fun test2() {}
@Foo([1f], [' '], [1])
@Foo([1f], <!ARGUMENT_TYPE_MISMATCH!>[' ']<!>, [1])
fun test3() {}
@Foo(c = [1f], b = [""], a = [1])
@@ -26,3 +26,15 @@ fun test7() {}
@Foo(<!NON_CONST_VAL_USED_IN_CONSTANT_EXPRESSION!>[<!NON_CONST_VAL_USED_IN_CONSTANT_EXPRESSION!>two<!>]<!>, [], [])
fun test8() {}
interface I<T>
class C<T> : I<T>
annotation class Test1<T>(val x: Int)
annotation class Test2<T1, T2 : I<T1>>(val x: Test1<I<T2>>)
@Repeatable annotation class Test3(val x: Array<Test2<Int, C<Int>>>)
@Test3(<!ARGUMENT_TYPE_MISMATCH!>[Test2<String, C<String>>(Test1(40))]<!>)
@Test3([Test2<Int, C<Int>>(Test1(40))])
@Test3([Test2(Test1(40))])
fun test9() {}
@@ -26,3 +26,15 @@ fun test7() {}
@Foo(<!NON_CONST_VAL_USED_IN_CONSTANT_EXPRESSION!>[<!NON_CONST_VAL_USED_IN_CONSTANT_EXPRESSION!>two<!>]<!>, [], [])
fun test8() {}
interface I<T>
class C<T> : I<T>
annotation class Test1<T>(val x: Int)
annotation class Test2<T1, T2 : I<T1>>(val x: Test1<I<T2>>)
@Repeatable annotation class Test3(val x: Array<Test2<Int, C<Int>>>)
@Test3(<!TYPE_MISMATCH!>[Test2<String, C<String>>(Test1(40))]<!>)
@Test3([Test2<Int, C<Int>>(Test1(40))])
@Test3([Test2(Test1(40))])
fun test9() {}
@@ -10,6 +10,14 @@ public val two: kotlin.Int = 2
@Foo(a = {1}, b = {}, c = {}) public fun test6(): kotlin.Unit
@Foo(a = {3}, b = {}, c = {}) public fun test7(): kotlin.Unit
@Foo(a = {2}, b = {}, c = {}) public fun test8(): kotlin.Unit
@Test3(x = {Test2<T1, T2>(x = Test1<T>(x = 40))}) @Test3(x = {Test2<T1, T2>(x = Test1<T>(x = 40))}) @Test3(x = {Test2<T1, T2>(x = Test1<T>(x = 40))}) public fun test9(): kotlin.Unit
public final class C</*0*/ T> : I<T> {
public constructor C</*0*/ T>()
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
}
public final annotation class Foo : kotlin.Annotation {
public constructor Foo(/*0*/ a: kotlin.IntArray, /*1*/ b: kotlin.Array<kotlin.String>, /*2*/ c: kotlin.FloatArray)
@@ -20,3 +28,34 @@ public final annotation class Foo : kotlin.Annotation {
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
}
public interface I</*0*/ T> {
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
}
public final annotation class Test1</*0*/ T> : kotlin.Annotation {
public constructor Test1</*0*/ T>(/*0*/ x: kotlin.Int)
public final val x: kotlin.Int
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
}
public final annotation class Test2</*0*/ T1, /*1*/ T2 : I<T1>> : kotlin.Annotation {
public constructor Test2</*0*/ T1, /*1*/ T2 : I<T1>>(/*0*/ x: Test1<I<T2>>)
public final val x: Test1<I<T2>>
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
}
@kotlin.annotation.Repeatable public final annotation class Test3 : kotlin.Annotation {
public constructor Test3(/*0*/ x: kotlin.Array<Test2<kotlin.Int, C<kotlin.Int>>>)
public final val x: kotlin.Array<Test2<kotlin.Int, C<kotlin.Int>>>
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
}
@@ -20,10 +20,10 @@ fun test3() {}
@Foo([<!CLASS_LITERAL_LHS_NOT_A_CLASS!>Gen<Int>::class<!>])
fun test4() {}
@Foo([""])
@Foo(<!ARGUMENT_TYPE_MISMATCH!>[""]<!>)
fun test5() {}
@Foo([Int::class, 1])
@Foo(<!ARGUMENT_TYPE_MISMATCH!>[Int::class, 1]<!>)
fun test6() {}
@Bar
@@ -16,7 +16,7 @@ fun test1_0() {}
@Ann1(*["a", "b"])
fun test1_1() {}
@Ann1(*["a", 1, null])
@Ann1(*<!ARGUMENT_TYPE_MISMATCH!>["a", 1, null]<!>)
fun test1_2() {}
@Ann2(*[])
@@ -36,5 +36,5 @@ annotation class AnnArray(val a: Array<String>)
@AnnArray(<!NON_VARARG_SPREAD!>*<!>["/"])
fun testArray() {}
@Ann1([""])
@Ann1(<!ARGUMENT_TYPE_MISMATCH!>[""]<!>)
fun testVararg() {}
@@ -19,7 +19,7 @@ fun test_fun(s: String, arr: Array<String>) {
}
fun test_ann(s: String, arr: Array<String>) {
@Ann([""], x = 1)
@Ann(<!ARGUMENT_TYPE_MISMATCH!>[""]<!>, x = 1)
foo()
@Ann(*[""], x = 1)
foo()
@@ -19,7 +19,7 @@ fun test_fun(s: String, arr: Array<String>) {
}
fun test_ann(s: String, arr: Array<String>) {
@Ann([""], x = 1)
@Ann(<!ARGUMENT_TYPE_MISMATCH!>[""]<!>, x = 1)
foo()
@Ann(*[""], x = 1)
foo()
@@ -222,7 +222,7 @@ FILE fqName:ann fileName:/genericAnnotationClasses.kt
Test1<ann.ARG>(x = '42')
Test2<kotlin.String, kotlin.String>(x = '38')
Test3<kotlin.String, ann.C<kotlin.String>>(x = Test1<ann.I<ann.C<kotlin.String>>>(x = '39'))
Test4(x = [Test3<IrErrorType(null), IrErrorType(null)>(x = Test1<IrErrorType(null)>(x = '40')), Test3<IrErrorType(null), IrErrorType(null)>(x = Test1<IrErrorType(null)>(x = '50')), Test3<IrErrorType(null), IrErrorType(null)>(x = Test1<IrErrorType(null)>(x = '60'))])
Test4(x = [Test3<kotlin.Int, ann.C<kotlin.Int>>(x = Test1<ann.I<ann.C<kotlin.Int>>>(x = '40')), Test3<kotlin.Int, ann.C<kotlin.Int>>(x = Test1<ann.I<ann.C<kotlin.Int>>>(x = '50')), Test3<kotlin.Int, ann.C<kotlin.Int>>(x = Test1<ann.I<ann.C<kotlin.Int>>>(x = '60'))])
Test5<ann.ARG>(xs = [Test3<ann.ARG, ann.C<ann.ARG>>(x = Test1<ann.I<ann.C<ann.ARG>>>(x = '70')), Test3<ann.ARG, ann.C<ann.ARG>>(x = Test1<ann.I<ann.C<ann.ARG>>>(x = '80'))])
$this: VALUE_PARAMETER INSTANCE_RECEIVER name:<this> type:ann.CC
CONSTRUCTOR visibility:public <> () returnType:ann.CC [primary]
@@ -90,7 +90,7 @@ open annotation class Test5<T : Any?> : Annotation {
@Test1<ARG>(x = 42)
@Test2<String, String>(x = 38)
@Test3<String, C<String>>(x = Test1<I<C<String>>>(x = 39))
@Test4(x = [Test3<ErrorType, ErrorType>(x = Test1<ErrorType>(x = 40)), Test3<ErrorType, ErrorType>(x = Test1<ErrorType>(x = 50)), Test3<ErrorType, ErrorType>(x = Test1<ErrorType>(x = 60))])
@Test4(x = [Test3<Int, C<Int>>(x = Test1<I<C<Int>>>(x = 40)), Test3<Int, C<Int>>(x = Test1<I<C<Int>>>(x = 50)), Test3<Int, C<Int>>(x = Test1<I<C<Int>>>(x = 60))])
@Test5<ARG>(xs = [Test3<ARG, C<ARG>>(x = Test1<I<C<ARG>>>(x = 70)), Test3<ARG, C<ARG>>(x = Test1<I<C<ARG>>>(x = 80))])
class CC {
constructor() /* primary */ {
@@ -1,5 +1,5 @@
// MUTE_SIGNATURE_COMPARISON_K2: ANY
// ^ KT-54517
// ^ KT-60136
package ann