Forbid non-intended usages of Experimental and markers
Experimental and UseExperimental can only be used as annotations or qualifiers (to allow "Experimental.Level.*"); experimental markers can only be used as annotations or qualifiers, or as left-hand side of a ::class literal in arguments to UseExperimental/WasExperimental. This is needed because we're not yet sure of the design of this feature and would like to retain the possibility to drop these declarations (Experimental, UseExperimental) altogether. If they were going to be used as types, it would be problematic because we can't simply delete something from stdlib, should deprecate it first. With this change, these declarations can only be used if the user has opted into using the experimental API somehow (for example, with `-Xuse-experimental=kotlin.Experimental`), so we won't stop conforming to our deprecation policy if we decide to remove these declarations in the future
This commit is contained in:
+54
@@ -0,0 +1,54 @@
|
||||
// !USE_EXPERIMENTAL: kotlin.Experimental
|
||||
// !DIAGNOSTICS: -UNUSED_PARAMETER
|
||||
|
||||
package test
|
||||
|
||||
import kotlin.reflect.KClass
|
||||
|
||||
// Usages in import should be OK
|
||||
import kotlin.Experimental.Level.*
|
||||
import kotlin.Experimental.Level
|
||||
import kotlin.Experimental
|
||||
|
||||
// Usages with FQ names should be OK
|
||||
|
||||
@kotlin.Experimental(kotlin.Experimental.Level.ERROR)
|
||||
annotation class M
|
||||
|
||||
|
||||
// Usages as types should be errors
|
||||
|
||||
fun f1(e: <!EXPERIMENTAL_CAN_ONLY_BE_USED_AS_ANNOTATION!>Experimental<!>) {}
|
||||
fun f2(u: <!EXPERIMENTAL_CAN_ONLY_BE_USED_AS_ANNOTATION!>UseExperimental<!>?) {}
|
||||
|
||||
typealias Experimental0 = <!EXPERIMENTAL_CAN_ONLY_BE_USED_AS_ANNOTATION!>Experimental<!>
|
||||
typealias UseExperimental0 = <!EXPERIMENTAL_CAN_ONLY_BE_USED_AS_ANNOTATION!>UseExperimental<!>
|
||||
fun f3(e: Experimental0 /* TODO */) {}
|
||||
fun f4(u: UseExperimental0 /* TODO */) {}
|
||||
|
||||
|
||||
// Usages as ::class literals should be errors
|
||||
|
||||
annotation class VarargKClasses(vararg val k: KClass<*>)
|
||||
|
||||
@VarargKClasses(
|
||||
<!EXPERIMENTAL_CAN_ONLY_BE_USED_AS_ANNOTATION!>Experimental<!>::class,
|
||||
<!EXPERIMENTAL_CAN_ONLY_BE_USED_AS_ANNOTATION!>UseExperimental<!>::class,
|
||||
kotlin.<!EXPERIMENTAL_CAN_ONLY_BE_USED_AS_ANNOTATION!>Experimental<!>::class,
|
||||
kotlin.<!EXPERIMENTAL_CAN_ONLY_BE_USED_AS_ANNOTATION!>UseExperimental<!>::class
|
||||
)
|
||||
fun f5() {}
|
||||
|
||||
|
||||
// Usages of markers as types should be errors
|
||||
|
||||
@Experimental
|
||||
annotation class Marker
|
||||
|
||||
fun f6(m: <!EXPERIMENTAL_MARKER_CAN_ONLY_BE_USED_AS_ANNOTATION_OR_ARGUMENT_IN_USE_EXPERIMENTAL!>Marker<!>) {}
|
||||
fun f7(): List<<!EXPERIMENTAL_MARKER_CAN_ONLY_BE_USED_AS_ANNOTATION_OR_ARGUMENT_IN_USE_EXPERIMENTAL!>Marker<!>>? = null
|
||||
fun f8(): test.<!EXPERIMENTAL_MARKER_CAN_ONLY_BE_USED_AS_ANNOTATION_OR_ARGUMENT_IN_USE_EXPERIMENTAL!>Marker<!>? = null
|
||||
|
||||
typealias Marker0 = <!EXPERIMENTAL_MARKER_CAN_ONLY_BE_USED_AS_ANNOTATION_OR_ARGUMENT_IN_USE_EXPERIMENTAL!>Marker<!>
|
||||
|
||||
fun f9(m: <!EXPERIMENTAL_MARKER_CAN_ONLY_BE_USED_AS_ANNOTATION_OR_ARGUMENT_IN_USE_EXPERIMENTAL!>Marker0<!>) {}
|
||||
Reference in New Issue
Block a user