Files
kotlin-fork/compiler/testData/loadJava/compiledKotlinWithStdlib/annotations/annotationClassDefaultValues.kt
T
Leonid Startsev c4255f9a9e [K2] Instantiation of annotations having default values for properties
This commit adds missing pieces for the puzzle:

Annotation instantiation feature uses IrProperty's initializer to instantiate
properties from other modules that have default values which weren't
specified on call site.

To support this feature properly, Fir2IrVisitor should fill LazyIrProperty's
backing field initializer with information from Fir.

To get this information into Fir, FirMemberDeserializer should be able to read
it from KotlinJvmBinaryClass with AnnotationLoaderVisitorImpl. (klibs are unsupported for now)

There's a catch with enum entries references: we can't access session.SymbolProvider to resolve it
because we're still at the deserialization stage, and it can cause StackOverflow if enum is nested in the
same class (see RequiresOptIn.Level). To mitigate this, a new FirEnumEntryDeserializedAccessExpression is produced
instead; it is later replaced with the correct reference in the Fir2IrVisitor.

^KT-58137 Fixed

Also add test to loadJava folder with annotations default values that
verifies metadata loading
2023-05-12 16:08:02 +00:00

32 lines
976 B
Kotlin
Vendored

// NO_CHECK_SOURCE_VS_BINARY
//^ While compiling source with K1, we do not store annotation default values, but we load them when reading compiled files both in K1 and K2
// This test verifies exactly loading of default values
package test
import kotlin.reflect.KClass
enum class E { E0 }
annotation class Empty
annotation class A(
val i: Int = 42,
val s: String = "foo",
val kClass: KClass<*> = Int::class,
val kClassArray: Array<KClass<*>> = [A::class],
val e: E = E.E0,
val anno: Empty = Empty(),
val aS: Array<String> = arrayOf("a", "b"),
val aI: IntArray = intArrayOf(1, 2)
)
annotation class OtherArrays(
val doublesArray: DoubleArray = [1.5],
val enumArray: Array<kotlin.text.RegexOption> = [kotlin.text.RegexOption.IGNORE_CASE],
val annotationsArray: Array<JvmStatic> = [],
val namesArray: Array<JvmName> = [JvmName("foo")]
)
annotation class UnsignedValue(
val uint: UInt = 2147483657U // Int.MAX_VALUE + 10
)