Files
kotlin-fork/compiler/testData/compileKotlinAgainstKotlin/optionalAnnotation.kt
T
Alexander Udalov 012ffa2993 Support new scheme of compilation of OptionalExpectation annotations
Instead of generating these annotation classes as package-private on
JVM, serialize their metadata to the .kotlin_module file, and load it
when compiling dependent multiplatform modules.

The problem with generating them as package-private was that
kotlin-stdlib for JVM would end up declaring symbols from other
platforms, which would include some annotations from package
kotlin.native. But using that package is discouraged by some tools
because it has a Java keyword in its name. In particular, jlink refused
to work with such artifact altogether (KT-21266).

 #KT-38652 Fixed
2020-05-12 19:28:57 +02:00

41 lines
935 B
Kotlin
Vendored

// !LANGUAGE: +MultiPlatformProjects
// !USE_EXPERIMENTAL: kotlin.ExperimentalMultiplatform
// TARGET_BACKEND: JVM
// FULL_JDK
// FILE: A.kt
package a
@OptionalExpectation
expect annotation class A(val x: Int)
@OptionalExpectation
expect annotation class B(val s: String)
actual annotation class A(actual val x: Int)
// FILE: B.kt
@file:Suppress("OPTIONAL_DECLARATION_USAGE_IN_NON_COMMON_SOURCE") // TODO: support common sources in the test infrastructure
import a.A
import a.B
import java.lang.reflect.Modifier
class Test {
@A(42)
@B("OK")
fun test() {}
}
fun box(): String {
val annotations = Test::class.java.declaredMethods.single().annotations.toList()
if (annotations.toString() != "[@a.A(x=42)]") return "Fail 1: $annotations"
try {
Class.forName("a.B")
return "Fail 2: there should be no class file for a.B"
} catch (e: ClassNotFoundException) {
return "OK"
}
}