From c57864e46caebff64b48b089548d998a1089dcdb Mon Sep 17 00:00:00 2001 From: Alexander Udalov Date: Fri, 27 Apr 2018 14:11:57 +0200 Subject: [PATCH] Require "-Xuse-experimental=kotlin.Experimental" on usages of Experimental Since we're not yet sure of the design of Experimental/UseExperimental, we're making them "experimental" themselves in some sense, in that the user is required to provide the magic argument "-Xuse-experimental=kotlin.Experimental" to be allowed to use either Experimental or UseExperimental. This is more convenient than the previous approach of "-language-version 1.3 -Xskip-metadata-version-check" because it's simpler and does not cause pre-release binaries to be produced --- .../jetbrains/kotlin/diagnostics/Errors.java | 1 + .../rendering/DefaultErrorMessages.java | 1 + .../checkers/ExperimentalUsageChecker.kt | 23 +++++++++++++- ...lAndUseExperimentalWithSameAnnotation.args | 4 +-- ...alAndUseExperimentalWithSameAnnotation.out | 1 - .../cli/jvm/experimentalDeprecated.args | 4 +-- .../cli/jvm/experimentalDeprecated.out | 1 - .../jvm/experimentalDeprecatedWarning.args | 4 +-- .../cli/jvm/experimentalDeprecatedWarning.out | 1 - .../testData/cli/jvm/experimentalNested.args | 4 +-- .../testData/cli/jvm/experimentalNested.out | 1 - .../experimental/annotation.kt | 2 +- .../experimental/bodyUsages.kt | 2 +- .../experimental/classMembers.kt | 2 +- .../classMembersOverlyExperimental.kt | 2 +- .../testsWithStdLib/experimental/constVal.kt | 2 +- .../experimental/deeplyNestedClass.kt | 2 +- .../testsWithStdLib/experimental/errors.kt | 2 +- .../experimental/experimentalIsNotEnabled.kt | 23 ++++++++++++++ .../experimental/experimentalIsNotEnabled.txt | 13 ++++++++ .../experimental/experimentalOnWholeModule.kt | 2 +- ...correctTargetsForExperimentalAnnotation.kt | 2 +- .../experimental/incorrectUseExperimental.kt | 2 +- .../testsWithStdLib/experimental/override.kt | 2 +- .../overrideDifferentExperimentalities.kt | 2 +- .../testsWithStdLib/experimental/scripts.kt | 2 +- .../testsWithStdLib/experimental/topLevel.kt | 2 +- .../testsWithStdLib/experimental/typealias.kt | 2 +- .../experimental/useExperimentalOnFile.kt | 2 +- ...imentalOnFileWithVeryExperimentalMarker.kt | 2 +- .../useExperimentalOnWholeModule.kt | 3 +- .../experimental/useExperimentalTargets.kt | 2 +- .../useExperimentalWithSeveralAnnotations.kt | 2 +- .../DiagnosticsTestWithStdLibGenerated.java | 5 +++ ...ticsTestWithStdLibUsingJavacGenerated.java | 5 +++ .../kotlin/codegen/JvmModuleProtoBufTest.kt | 4 +-- .../compiler/ExperimentalIntegrationTest.kt | 15 +++------ .../resolve/MultiModuleHighlightingTest.kt | 31 ++++--------------- libraries/stdlib/js/build.gradle | 10 +++--- .../kotlin/annotations/Experimental.kt | 12 +++++-- .../RuntimePublicAPITest.kt | 2 +- 41 files changed, 121 insertions(+), 85 deletions(-) create mode 100644 compiler/testData/diagnostics/testsWithStdLib/experimental/experimentalIsNotEnabled.kt create mode 100644 compiler/testData/diagnostics/testsWithStdLib/experimental/experimentalIsNotEnabled.txt rename libraries/stdlib/{experimental => src}/kotlin/annotations/Experimental.kt (77%) diff --git a/compiler/frontend/src/org/jetbrains/kotlin/diagnostics/Errors.java b/compiler/frontend/src/org/jetbrains/kotlin/diagnostics/Errors.java index 9d12d432d4d..f916e01e728 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/diagnostics/Errors.java +++ b/compiler/frontend/src/org/jetbrains/kotlin/diagnostics/Errors.java @@ -240,6 +240,7 @@ public interface Errors { DiagnosticFactory2 EXPERIMENTAL_OVERRIDE = DiagnosticFactory2.create(WARNING); DiagnosticFactory2 EXPERIMENTAL_OVERRIDE_ERROR = DiagnosticFactory2.create(ERROR); + DiagnosticFactory0 EXPERIMENTAL_IS_NOT_ENABLED = DiagnosticFactory0.create(ERROR); DiagnosticFactory0 USE_EXPERIMENTAL_WITHOUT_ARGUMENTS = DiagnosticFactory0.create(WARNING); DiagnosticFactory1 USE_EXPERIMENTAL_ARGUMENT_IS_NOT_MARKER = DiagnosticFactory1.create(WARNING); DiagnosticFactory1 EXPERIMENTAL_ANNOTATION_WITH_WRONG_TARGET = DiagnosticFactory1.create(ERROR); diff --git a/compiler/frontend/src/org/jetbrains/kotlin/diagnostics/rendering/DefaultErrorMessages.java b/compiler/frontend/src/org/jetbrains/kotlin/diagnostics/rendering/DefaultErrorMessages.java index 0e1deb8106c..66d814d956c 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/diagnostics/rendering/DefaultErrorMessages.java +++ b/compiler/frontend/src/org/jetbrains/kotlin/diagnostics/rendering/DefaultErrorMessages.java @@ -146,6 +146,7 @@ public class DefaultErrorMessages { MAP.put(EXPERIMENTAL_OVERRIDE, "This declaration overrides experimental member of supertype ''{1}'' and should be annotated with ''@{0}''", TO_STRING, NAME); MAP.put(EXPERIMENTAL_OVERRIDE_ERROR, "This declaration overrides experimental member of supertype ''{1}'' and must be annotated with ''@{0}''", TO_STRING, NAME); + MAP.put(EXPERIMENTAL_IS_NOT_ENABLED, "This class can only be used with the compiler argument '-Xuse-experimental=kotlin.Experimental'"); MAP.put(USE_EXPERIMENTAL_WITHOUT_ARGUMENTS, "@UseExperimental without any arguments has no effect"); MAP.put(USE_EXPERIMENTAL_ARGUMENT_IS_NOT_MARKER, "Annotation ''{0}'' is not an experimental API marker, therefore its usage in @UseExperimental is ignored", TO_STRING); MAP.put(EXPERIMENTAL_ANNOTATION_WITH_WRONG_TARGET, "Experimental annotation cannot be used on the following code elements: {0}. Please remove these targets", STRING); diff --git a/compiler/frontend/src/org/jetbrains/kotlin/resolve/checkers/ExperimentalUsageChecker.kt b/compiler/frontend/src/org/jetbrains/kotlin/resolve/checkers/ExperimentalUsageChecker.kt index fe43c0ef61c..a0e002982f2 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/resolve/checkers/ExperimentalUsageChecker.kt +++ b/compiler/frontend/src/org/jetbrains/kotlin/resolve/checkers/ExperimentalUsageChecker.kt @@ -37,6 +37,7 @@ import org.jetbrains.kotlin.resolve.constants.EnumValue import org.jetbrains.kotlin.resolve.constants.KClassValue import org.jetbrains.kotlin.resolve.descriptorUtil.annotationClass import org.jetbrains.kotlin.resolve.descriptorUtil.fqNameSafe +import org.jetbrains.kotlin.resolve.descriptorUtil.fqNameUnsafe import org.jetbrains.kotlin.resolve.descriptorUtil.module import org.jetbrains.kotlin.storage.LockBasedStorageManager import org.jetbrains.kotlin.utils.SmartSet @@ -67,6 +68,9 @@ class ExperimentalUsageChecker(project: Project) : CallChecker { private val WARNING_LEVEL = Name.identifier("WARNING") private val ERROR_LEVEL = Name.identifier("ERROR") + private val EXPERIMENTAL_SHORT_NAME = EXPERIMENTAL_FQ_NAME.shortName() + private val USE_EXPERIMENTAL_SHORT_NAME = USE_EXPERIMENTAL_FQ_NAME.shortName() + private fun reportNotAcceptedExperimentalities( experimentalities: Collection, element: PsiElement, context: CheckerContext ) { @@ -196,7 +200,9 @@ class ExperimentalUsageChecker(project: Project) : CallChecker { } val validExperimental = languageVersionSettings.getFlag(AnalysisFlag.experimental).filter(::checkAnnotation) - val validUseExperimental = languageVersionSettings.getFlag(AnalysisFlag.useExperimental).filter(::checkAnnotation) + val validUseExperimental = languageVersionSettings.getFlag(AnalysisFlag.useExperimental).filter { fqName -> + fqName == EXPERIMENTAL_FQ_NAME.asString() || checkAnnotation(fqName) + } for (fqName in validExperimental.intersect(validUseExperimental)) { reportError("'-Xuse-experimental=$fqName' has no effect because '-Xexperimental=$fqName' is used") @@ -208,9 +214,24 @@ class ExperimentalUsageChecker(project: Project) : CallChecker { private val moduleAnnotationsResolver = ModuleAnnotationsResolver.getInstance(project) override fun check(targetDescriptor: ClassifierDescriptor, element: PsiElement, context: ClassifierUsageCheckerContext) { + val name = targetDescriptor.name + if (name == EXPERIMENTAL_SHORT_NAME || name == USE_EXPERIMENTAL_SHORT_NAME) { + val fqName = targetDescriptor.fqNameUnsafe + if (fqName == EXPERIMENTAL_FQ_NAME.toUnsafe() || fqName == USE_EXPERIMENTAL_FQ_NAME.toUnsafe()) { + checkUsageOfKotlinExperimentalOrUseExperimental(element, context) + return + } + } + val experimentalities = targetDescriptor.loadExperimentalities(moduleAnnotationsResolver) reportNotAcceptedExperimentalities(experimentalities, element, context) } + + private fun checkUsageOfKotlinExperimentalOrUseExperimental(element: PsiElement, context: CheckerContext) { + if (EXPERIMENTAL_FQ_NAME.asString() !in context.languageVersionSettings.getFlag(AnalysisFlag.useExperimental)) { + context.trace.report(Errors.EXPERIMENTAL_IS_NOT_ENABLED.on(element)) + } + } } class Overrides(project: Project) : DeclarationChecker { diff --git a/compiler/testData/cli/jvm/experimentalAndUseExperimentalWithSameAnnotation.args b/compiler/testData/cli/jvm/experimentalAndUseExperimentalWithSameAnnotation.args index 09db7a95795..d54ee0e360c 100644 --- a/compiler/testData/cli/jvm/experimentalAndUseExperimentalWithSameAnnotation.args +++ b/compiler/testData/cli/jvm/experimentalAndUseExperimentalWithSameAnnotation.args @@ -1,8 +1,6 @@ $TESTDATA_DIR$/experimentalAndUseExperimentalWithSameAnnotation.kt -d $TEMP_DIR$ --Xskip-runtime-version-check --language-version -1.3 +-Xuse-experimental=kotlin.Experimental -Xexperimental=org.test.ExperimentalAPI -Xuse-experimental=org.test.ExperimentalAPI diff --git a/compiler/testData/cli/jvm/experimentalAndUseExperimentalWithSameAnnotation.out b/compiler/testData/cli/jvm/experimentalAndUseExperimentalWithSameAnnotation.out index 60424dc0d8a..fb8dd5e37fe 100644 --- a/compiler/testData/cli/jvm/experimentalAndUseExperimentalWithSameAnnotation.out +++ b/compiler/testData/cli/jvm/experimentalAndUseExperimentalWithSameAnnotation.out @@ -1,3 +1,2 @@ -warning: language version 1.3 is experimental, there are no backwards compatibility guarantees for new language and library features error: '-Xuse-experimental=org.test.ExperimentalAPI' has no effect because '-Xexperimental=org.test.ExperimentalAPI' is used COMPILATION_ERROR diff --git a/compiler/testData/cli/jvm/experimentalDeprecated.args b/compiler/testData/cli/jvm/experimentalDeprecated.args index b0dfe4977f8..733cfeea9f6 100644 --- a/compiler/testData/cli/jvm/experimentalDeprecated.args +++ b/compiler/testData/cli/jvm/experimentalDeprecated.args @@ -1,9 +1,7 @@ $TESTDATA_DIR$/experimentalDeprecated.kt -d $TEMP_DIR$ --Xskip-runtime-version-check --language-version -1.3 +-Xuse-experimental=kotlin.Experimental -Xexperimental=org.test.Error1 -Xexperimental=org.test.Hidden1 -Xuse-experimental=org.test.Error2 diff --git a/compiler/testData/cli/jvm/experimentalDeprecated.out b/compiler/testData/cli/jvm/experimentalDeprecated.out index 9efde113798..6208f5328d8 100644 --- a/compiler/testData/cli/jvm/experimentalDeprecated.out +++ b/compiler/testData/cli/jvm/experimentalDeprecated.out @@ -1,4 +1,3 @@ -warning: language version 1.3 is experimental, there are no backwards compatibility guarantees for new language and library features error: experimental API marker org.test.Error1 is deprecated. Error1 error: experimental API marker org.test.Hidden1 is deprecated. Hidden1 error: experimental API marker org.test.Error2 is deprecated. Error2 diff --git a/compiler/testData/cli/jvm/experimentalDeprecatedWarning.args b/compiler/testData/cli/jvm/experimentalDeprecatedWarning.args index 83d37b2440a..8cece954a32 100644 --- a/compiler/testData/cli/jvm/experimentalDeprecatedWarning.args +++ b/compiler/testData/cli/jvm/experimentalDeprecatedWarning.args @@ -1,8 +1,6 @@ $TESTDATA_DIR$/experimentalDeprecatedWarning.kt -d $TEMP_DIR$ --Xskip-runtime-version-check --language-version -1.3 +-Xuse-experimental=kotlin.Experimental -Xuse-experimental=org.test.Warning1 -Xexperimental=org.test.Warning2 diff --git a/compiler/testData/cli/jvm/experimentalDeprecatedWarning.out b/compiler/testData/cli/jvm/experimentalDeprecatedWarning.out index ec7d5b5b3db..f03ea066f9d 100644 --- a/compiler/testData/cli/jvm/experimentalDeprecatedWarning.out +++ b/compiler/testData/cli/jvm/experimentalDeprecatedWarning.out @@ -1,4 +1,3 @@ -warning: language version 1.3 is experimental, there are no backwards compatibility guarantees for new language and library features warning: experimental API marker org.test.Warning2 is deprecated. Warning2 warning: experimental API marker org.test.Warning1 is deprecated. Warning1 OK diff --git a/compiler/testData/cli/jvm/experimentalNested.args b/compiler/testData/cli/jvm/experimentalNested.args index 89300241959..649751ca75e 100644 --- a/compiler/testData/cli/jvm/experimentalNested.args +++ b/compiler/testData/cli/jvm/experimentalNested.args @@ -1,7 +1,5 @@ $TESTDATA_DIR$/experimentalNested.kt -d $TEMP_DIR$ --Xskip-runtime-version-check --language-version -1.3 +-Xuse-experimental=kotlin.Experimental -Xexperimental=org.test.Outer.Nested diff --git a/compiler/testData/cli/jvm/experimentalNested.out b/compiler/testData/cli/jvm/experimentalNested.out index 9d544c3eab0..d86bac9de59 100644 --- a/compiler/testData/cli/jvm/experimentalNested.out +++ b/compiler/testData/cli/jvm/experimentalNested.out @@ -1,2 +1 @@ -warning: language version 1.3 is experimental, there are no backwards compatibility guarantees for new language and library features OK diff --git a/compiler/testData/diagnostics/testsWithStdLib/experimental/annotation.kt b/compiler/testData/diagnostics/testsWithStdLib/experimental/annotation.kt index 39a6cfbbd28..61e114d2d4e 100644 --- a/compiler/testData/diagnostics/testsWithStdLib/experimental/annotation.kt +++ b/compiler/testData/diagnostics/testsWithStdLib/experimental/annotation.kt @@ -1,4 +1,4 @@ -// !API_VERSION: 1.3 +// !USE_EXPERIMENTAL: kotlin.Experimental // !DIAGNOSTICS: -UNUSED_PARAMETER // FILE: api.kt diff --git a/compiler/testData/diagnostics/testsWithStdLib/experimental/bodyUsages.kt b/compiler/testData/diagnostics/testsWithStdLib/experimental/bodyUsages.kt index 8b94e01a6d7..0e2663bf6bd 100644 --- a/compiler/testData/diagnostics/testsWithStdLib/experimental/bodyUsages.kt +++ b/compiler/testData/diagnostics/testsWithStdLib/experimental/bodyUsages.kt @@ -1,4 +1,4 @@ -// !API_VERSION: 1.3 +// !USE_EXPERIMENTAL: kotlin.Experimental // FILE: api.kt package api diff --git a/compiler/testData/diagnostics/testsWithStdLib/experimental/classMembers.kt b/compiler/testData/diagnostics/testsWithStdLib/experimental/classMembers.kt index 499a95711a8..fb217d7d6e0 100644 --- a/compiler/testData/diagnostics/testsWithStdLib/experimental/classMembers.kt +++ b/compiler/testData/diagnostics/testsWithStdLib/experimental/classMembers.kt @@ -1,4 +1,4 @@ -// !API_VERSION: 1.3 +// !USE_EXPERIMENTAL: kotlin.Experimental // FILE: api.kt package api diff --git a/compiler/testData/diagnostics/testsWithStdLib/experimental/classMembersOverlyExperimental.kt b/compiler/testData/diagnostics/testsWithStdLib/experimental/classMembersOverlyExperimental.kt index 5a0df9542d8..5e696c60714 100644 --- a/compiler/testData/diagnostics/testsWithStdLib/experimental/classMembersOverlyExperimental.kt +++ b/compiler/testData/diagnostics/testsWithStdLib/experimental/classMembersOverlyExperimental.kt @@ -1,4 +1,4 @@ -// !API_VERSION: 1.3 +// !USE_EXPERIMENTAL: kotlin.Experimental // FILE: api.kt package api diff --git a/compiler/testData/diagnostics/testsWithStdLib/experimental/constVal.kt b/compiler/testData/diagnostics/testsWithStdLib/experimental/constVal.kt index 2e0db195270..7d042dddf61 100644 --- a/compiler/testData/diagnostics/testsWithStdLib/experimental/constVal.kt +++ b/compiler/testData/diagnostics/testsWithStdLib/experimental/constVal.kt @@ -1,4 +1,4 @@ -// !API_VERSION: 1.3 +// !USE_EXPERIMENTAL: kotlin.Experimental // FILE: api.kt package api diff --git a/compiler/testData/diagnostics/testsWithStdLib/experimental/deeplyNestedClass.kt b/compiler/testData/diagnostics/testsWithStdLib/experimental/deeplyNestedClass.kt index 942b9cb6f1a..b6c94ec2ddf 100644 --- a/compiler/testData/diagnostics/testsWithStdLib/experimental/deeplyNestedClass.kt +++ b/compiler/testData/diagnostics/testsWithStdLib/experimental/deeplyNestedClass.kt @@ -1,4 +1,4 @@ -// !API_VERSION: 1.3 +// !USE_EXPERIMENTAL: kotlin.Experimental // FILE: api.kt package api diff --git a/compiler/testData/diagnostics/testsWithStdLib/experimental/errors.kt b/compiler/testData/diagnostics/testsWithStdLib/experimental/errors.kt index 657f28ca34e..434c7f1c6e6 100644 --- a/compiler/testData/diagnostics/testsWithStdLib/experimental/errors.kt +++ b/compiler/testData/diagnostics/testsWithStdLib/experimental/errors.kt @@ -1,4 +1,4 @@ -// !API_VERSION: 1.3 +// !USE_EXPERIMENTAL: kotlin.Experimental // FILE: api.kt package api diff --git a/compiler/testData/diagnostics/testsWithStdLib/experimental/experimentalIsNotEnabled.kt b/compiler/testData/diagnostics/testsWithStdLib/experimental/experimentalIsNotEnabled.kt new file mode 100644 index 00000000000..0f6612355ab --- /dev/null +++ b/compiler/testData/diagnostics/testsWithStdLib/experimental/experimentalIsNotEnabled.kt @@ -0,0 +1,23 @@ +// FILE: api.kt + +@Experimental +annotation class Marker + +@Marker +fun f() {} + +// FILE: usage.kt + +fun use1() { + f() +} + +@Marker +fun use2() { + f() +} + +@UseExperimental(Marker::class) +fun use3() { + f() +} diff --git a/compiler/testData/diagnostics/testsWithStdLib/experimental/experimentalIsNotEnabled.txt b/compiler/testData/diagnostics/testsWithStdLib/experimental/experimentalIsNotEnabled.txt new file mode 100644 index 00000000000..43578fca0a9 --- /dev/null +++ b/compiler/testData/diagnostics/testsWithStdLib/experimental/experimentalIsNotEnabled.txt @@ -0,0 +1,13 @@ +package + +@Marker public fun f(): kotlin.Unit +public fun use1(): kotlin.Unit +@Marker public fun use2(): kotlin.Unit +@kotlin.UseExperimental(markerClass = {Marker::class}) public fun use3(): kotlin.Unit + +@kotlin.Experimental public final annotation class Marker : kotlin.Annotation { + public constructor Marker() + 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 +} diff --git a/compiler/testData/diagnostics/testsWithStdLib/experimental/experimentalOnWholeModule.kt b/compiler/testData/diagnostics/testsWithStdLib/experimental/experimentalOnWholeModule.kt index c5c23adb144..b05884b7a67 100644 --- a/compiler/testData/diagnostics/testsWithStdLib/experimental/experimentalOnWholeModule.kt +++ b/compiler/testData/diagnostics/testsWithStdLib/experimental/experimentalOnWholeModule.kt @@ -1,4 +1,4 @@ -// !API_VERSION: 1.3 +// !USE_EXPERIMENTAL: kotlin.Experimental // !EXPERIMENTAL: api.ExperimentalAPI // MODULE: api // FILE: api.kt diff --git a/compiler/testData/diagnostics/testsWithStdLib/experimental/incorrectTargetsForExperimentalAnnotation.kt b/compiler/testData/diagnostics/testsWithStdLib/experimental/incorrectTargetsForExperimentalAnnotation.kt index 9751e751d79..b71155e3313 100644 --- a/compiler/testData/diagnostics/testsWithStdLib/experimental/incorrectTargetsForExperimentalAnnotation.kt +++ b/compiler/testData/diagnostics/testsWithStdLib/experimental/incorrectTargetsForExperimentalAnnotation.kt @@ -1,4 +1,4 @@ -// !API_VERSION: 1.3 +// !USE_EXPERIMENTAL: kotlin.Experimental // FILE: api.kt package api diff --git a/compiler/testData/diagnostics/testsWithStdLib/experimental/incorrectUseExperimental.kt b/compiler/testData/diagnostics/testsWithStdLib/experimental/incorrectUseExperimental.kt index fb23eeeca8d..5c022771e41 100644 --- a/compiler/testData/diagnostics/testsWithStdLib/experimental/incorrectUseExperimental.kt +++ b/compiler/testData/diagnostics/testsWithStdLib/experimental/incorrectUseExperimental.kt @@ -1,4 +1,4 @@ -// !API_VERSION: 1.3 +// !USE_EXPERIMENTAL: kotlin.Experimental @UseExperimental fun f1() {} diff --git a/compiler/testData/diagnostics/testsWithStdLib/experimental/override.kt b/compiler/testData/diagnostics/testsWithStdLib/experimental/override.kt index 74b8b2930c5..d6982906597 100644 --- a/compiler/testData/diagnostics/testsWithStdLib/experimental/override.kt +++ b/compiler/testData/diagnostics/testsWithStdLib/experimental/override.kt @@ -1,4 +1,4 @@ -// !API_VERSION: 1.3 +// !USE_EXPERIMENTAL: kotlin.Experimental // FILE: api.kt package api diff --git a/compiler/testData/diagnostics/testsWithStdLib/experimental/overrideDifferentExperimentalities.kt b/compiler/testData/diagnostics/testsWithStdLib/experimental/overrideDifferentExperimentalities.kt index 72a7eb05a4c..340b13b50fd 100644 --- a/compiler/testData/diagnostics/testsWithStdLib/experimental/overrideDifferentExperimentalities.kt +++ b/compiler/testData/diagnostics/testsWithStdLib/experimental/overrideDifferentExperimentalities.kt @@ -1,4 +1,4 @@ -// !API_VERSION: 1.3 +// !USE_EXPERIMENTAL: kotlin.Experimental @Experimental(Experimental.Level.WARNING) annotation class E1 diff --git a/compiler/testData/diagnostics/testsWithStdLib/experimental/scripts.kt b/compiler/testData/diagnostics/testsWithStdLib/experimental/scripts.kt index f6b19839a77..0995f670339 100644 --- a/compiler/testData/diagnostics/testsWithStdLib/experimental/scripts.kt +++ b/compiler/testData/diagnostics/testsWithStdLib/experimental/scripts.kt @@ -1,4 +1,4 @@ -// !API_VERSION: 1.3 +// !USE_EXPERIMENTAL: kotlin.Experimental // !DIAGNOSTICS: -UNUSED_VARIABLE // FILE: api.kt diff --git a/compiler/testData/diagnostics/testsWithStdLib/experimental/topLevel.kt b/compiler/testData/diagnostics/testsWithStdLib/experimental/topLevel.kt index 42dbb4c17e7..60a441da5f7 100644 --- a/compiler/testData/diagnostics/testsWithStdLib/experimental/topLevel.kt +++ b/compiler/testData/diagnostics/testsWithStdLib/experimental/topLevel.kt @@ -1,4 +1,4 @@ -// !API_VERSION: 1.3 +// !USE_EXPERIMENTAL: kotlin.Experimental // !DIAGNOSTICS: -UNUSED_VARIABLE // FILE: api.kt diff --git a/compiler/testData/diagnostics/testsWithStdLib/experimental/typealias.kt b/compiler/testData/diagnostics/testsWithStdLib/experimental/typealias.kt index a0ad16616da..3b8902c9a3a 100644 --- a/compiler/testData/diagnostics/testsWithStdLib/experimental/typealias.kt +++ b/compiler/testData/diagnostics/testsWithStdLib/experimental/typealias.kt @@ -1,4 +1,4 @@ -// !API_VERSION: 1.3 +// !USE_EXPERIMENTAL: kotlin.Experimental // FILE: api.kt package api diff --git a/compiler/testData/diagnostics/testsWithStdLib/experimental/useExperimentalOnFile.kt b/compiler/testData/diagnostics/testsWithStdLib/experimental/useExperimentalOnFile.kt index 8b20fdbf2e9..59004a5b0ac 100644 --- a/compiler/testData/diagnostics/testsWithStdLib/experimental/useExperimentalOnFile.kt +++ b/compiler/testData/diagnostics/testsWithStdLib/experimental/useExperimentalOnFile.kt @@ -1,4 +1,4 @@ -// !API_VERSION: 1.3 +// !USE_EXPERIMENTAL: kotlin.Experimental // FILE: api.kt package api diff --git a/compiler/testData/diagnostics/testsWithStdLib/experimental/useExperimentalOnFileWithVeryExperimentalMarker.kt b/compiler/testData/diagnostics/testsWithStdLib/experimental/useExperimentalOnFileWithVeryExperimentalMarker.kt index bed00a78875..02dea53ad33 100644 --- a/compiler/testData/diagnostics/testsWithStdLib/experimental/useExperimentalOnFileWithVeryExperimentalMarker.kt +++ b/compiler/testData/diagnostics/testsWithStdLib/experimental/useExperimentalOnFileWithVeryExperimentalMarker.kt @@ -1,4 +1,4 @@ -// !API_VERSION: 1.3 +// !USE_EXPERIMENTAL: kotlin.Experimental // FILE: api.kt package api diff --git a/compiler/testData/diagnostics/testsWithStdLib/experimental/useExperimentalOnWholeModule.kt b/compiler/testData/diagnostics/testsWithStdLib/experimental/useExperimentalOnWholeModule.kt index c327e2a75ab..ceef76351ea 100644 --- a/compiler/testData/diagnostics/testsWithStdLib/experimental/useExperimentalOnWholeModule.kt +++ b/compiler/testData/diagnostics/testsWithStdLib/experimental/useExperimentalOnWholeModule.kt @@ -1,5 +1,4 @@ -// !API_VERSION: 1.3 -// !USE_EXPERIMENTAL: api.ExperimentalAPI +// !USE_EXPERIMENTAL: kotlin.Experimental api.ExperimentalAPI // MODULE: api // FILE: api.kt diff --git a/compiler/testData/diagnostics/testsWithStdLib/experimental/useExperimentalTargets.kt b/compiler/testData/diagnostics/testsWithStdLib/experimental/useExperimentalTargets.kt index b96f66066ac..03ac37da9e2 100644 --- a/compiler/testData/diagnostics/testsWithStdLib/experimental/useExperimentalTargets.kt +++ b/compiler/testData/diagnostics/testsWithStdLib/experimental/useExperimentalTargets.kt @@ -1,4 +1,4 @@ -// !API_VERSION: 1.3 +// !USE_EXPERIMENTAL: kotlin.Experimental // !DIAGNOSTICS: -UNUSED_PARAMETER // FILE: api.kt diff --git a/compiler/testData/diagnostics/testsWithStdLib/experimental/useExperimentalWithSeveralAnnotations.kt b/compiler/testData/diagnostics/testsWithStdLib/experimental/useExperimentalWithSeveralAnnotations.kt index bba7affe7a6..00bfb618c87 100644 --- a/compiler/testData/diagnostics/testsWithStdLib/experimental/useExperimentalWithSeveralAnnotations.kt +++ b/compiler/testData/diagnostics/testsWithStdLib/experimental/useExperimentalWithSeveralAnnotations.kt @@ -1,4 +1,4 @@ -// !API_VERSION: 1.3 +// !USE_EXPERIMENTAL: kotlin.Experimental // FILE: api.kt package api diff --git a/compiler/tests/org/jetbrains/kotlin/checkers/DiagnosticsTestWithStdLibGenerated.java b/compiler/tests/org/jetbrains/kotlin/checkers/DiagnosticsTestWithStdLibGenerated.java index 36466ed296f..1f0faf1d5b0 100644 --- a/compiler/tests/org/jetbrains/kotlin/checkers/DiagnosticsTestWithStdLibGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/checkers/DiagnosticsTestWithStdLibGenerated.java @@ -2112,6 +2112,11 @@ public class DiagnosticsTestWithStdLibGenerated extends AbstractDiagnosticsTestW runTest("compiler/testData/diagnostics/testsWithStdLib/experimental/errors.kt"); } + @TestMetadata("experimentalIsNotEnabled.kt") + public void testExperimentalIsNotEnabled() throws Exception { + runTest("compiler/testData/diagnostics/testsWithStdLib/experimental/experimentalIsNotEnabled.kt"); + } + @TestMetadata("experimentalOnWholeModule.kt") public void testExperimentalOnWholeModule() throws Exception { runTest("compiler/testData/diagnostics/testsWithStdLib/experimental/experimentalOnWholeModule.kt"); diff --git a/compiler/tests/org/jetbrains/kotlin/checkers/javac/DiagnosticsTestWithStdLibUsingJavacGenerated.java b/compiler/tests/org/jetbrains/kotlin/checkers/javac/DiagnosticsTestWithStdLibUsingJavacGenerated.java index 048d23513b4..c223c88021e 100644 --- a/compiler/tests/org/jetbrains/kotlin/checkers/javac/DiagnosticsTestWithStdLibUsingJavacGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/checkers/javac/DiagnosticsTestWithStdLibUsingJavacGenerated.java @@ -2112,6 +2112,11 @@ public class DiagnosticsTestWithStdLibUsingJavacGenerated extends AbstractDiagno runTest("compiler/testData/diagnostics/testsWithStdLib/experimental/errors.kt"); } + @TestMetadata("experimentalIsNotEnabled.kt") + public void testExperimentalIsNotEnabled() throws Exception { + runTest("compiler/testData/diagnostics/testsWithStdLib/experimental/experimentalIsNotEnabled.kt"); + } + @TestMetadata("experimentalOnWholeModule.kt") public void testExperimentalOnWholeModule() throws Exception { runTest("compiler/testData/diagnostics/testsWithStdLib/experimental/experimentalOnWholeModule.kt"); diff --git a/compiler/tests/org/jetbrains/kotlin/codegen/JvmModuleProtoBufTest.kt b/compiler/tests/org/jetbrains/kotlin/codegen/JvmModuleProtoBufTest.kt index 44e689b9799..a4265b67621 100644 --- a/compiler/tests/org/jetbrains/kotlin/codegen/JvmModuleProtoBufTest.kt +++ b/compiler/tests/org/jetbrains/kotlin/codegen/JvmModuleProtoBufTest.kt @@ -97,9 +97,7 @@ class JvmModuleProtoBufTest : KtUsefulTestCase() { fun testExperimental() { doTest( "/moduleProtoBuf/experimental", extraOptions = listOf( - "-Xskip-runtime-version-check", - "-language-version", - "1.3", + "-Xuse-experimental=kotlin.Experimental", "-Xexperimental=org.foo.A", "-Xexperimental=org.foo.B.C", "-Xuse-experimental=org.foo.D" diff --git a/compiler/tests/org/jetbrains/kotlin/jvm/compiler/ExperimentalIntegrationTest.kt b/compiler/tests/org/jetbrains/kotlin/jvm/compiler/ExperimentalIntegrationTest.kt index 6fc3c340410..084f7f01a08 100644 --- a/compiler/tests/org/jetbrains/kotlin/jvm/compiler/ExperimentalIntegrationTest.kt +++ b/compiler/tests/org/jetbrains/kotlin/jvm/compiler/ExperimentalIntegrationTest.kt @@ -15,29 +15,22 @@ class ExperimentalIntegrationTest : AbstractKotlinCompilerIntegrationTest() { fun testJvmExperimentalModule() { val lib = compileLibrary( "lib", additionalOptions = listOf( - "-Xskip-runtime-version-check", - "-language-version", - "1.3", + "-Xuse-experimental=kotlin.Experimental", "-Xexperimental=lib.ExperimentalAPI" ), checkKotlinOutput = { output -> assertTrue(output, output.trimEnd().endsWith("OK")) } ) - compileKotlin("usage.kt", tmpdir, listOf(lib), additionalOptions = listOf("-Xskip-metadata-version-check")) + compileKotlin("usage.kt", tmpdir, listOf(lib)) } fun testJsExperimentalModule() { val lib = compileJsLibrary( "lib", additionalOptions = listOf( - "-Xskip-runtime-version-check", - "-language-version", - "1.3", + "-Xuse-experimental=kotlin.Experimental", "-Xexperimental=lib.ExperimentalAPI" ), checkKotlinOutput = { output -> assertTrue(output, output.trimEnd().endsWith("OK")) } ) - compileKotlin( - "usage.kt", File(tmpdir, "usage.js"), listOf(lib), K2JSCompiler(), - additionalOptions = listOf("-Xskip-metadata-version-check") - ) + compileKotlin("usage.kt", File(tmpdir, "usage.js"), listOf(lib), K2JSCompiler()) } } diff --git a/idea/tests/org/jetbrains/kotlin/idea/caches/resolve/MultiModuleHighlightingTest.kt b/idea/tests/org/jetbrains/kotlin/idea/caches/resolve/MultiModuleHighlightingTest.kt index 2c965e20b11..e5a21a56a84 100644 --- a/idea/tests/org/jetbrains/kotlin/idea/caches/resolve/MultiModuleHighlightingTest.kt +++ b/idea/tests/org/jetbrains/kotlin/idea/caches/resolve/MultiModuleHighlightingTest.kt @@ -33,7 +33,6 @@ import org.jetbrains.kotlin.cli.common.arguments.K2JVMCompilerArguments import org.jetbrains.kotlin.config.LanguageVersion import org.jetbrains.kotlin.idea.caches.project.ModuleSourceInfo import org.jetbrains.kotlin.idea.caches.project.SdkInfo -import org.jetbrains.kotlin.idea.compiler.configuration.KotlinCommonCompilerArgumentsHolder import org.jetbrains.kotlin.idea.completion.test.withServiceRegistered import org.jetbrains.kotlin.idea.facet.KotlinFacetConfiguration import org.jetbrains.kotlin.idea.facet.KotlinFacetType @@ -218,42 +217,24 @@ open class MultiModuleHighlightingTest : AbstractMultiModuleHighlightingTest() { val lib = MockLibraryUtil.compileJvmLibraryToJar( testDataPath + "${getTestName(true)}/lib", "lib", extraOptions = listOf( - "-Xskip-runtime-version-check", - "-language-version", - "1.3", + "-Xuse-experimental=kotlin.Experimental", "-Xexperimental=lib.ExperimentalAPI" ) ) - withSkipMetadataVersionCheck { - module("usage").addLibrary(lib) - checkHighlightingInAllFiles() - } + module("usage").addLibrary(lib) + checkHighlightingInAllFiles() } fun testJsExperimentalLibrary() { val lib = MockLibraryUtil.compileJsLibraryToJar( testDataPath + "${getTestName(true)}/lib", "lib", false, extraOptions = listOf( - "-Xskip-runtime-version-check", - "-language-version", - "1.3", + "-Xuse-experimental=kotlin.Experimental", "-Xexperimental=lib.ExperimentalAPI" ) ) - withSkipMetadataVersionCheck { - module("usage").addLibrary(lib, kind = JSLibraryKind) - checkHighlightingInAllFiles() - } - } - - private fun withSkipMetadataVersionCheck(block: () -> Unit) { - val holder = KotlinCommonCompilerArgumentsHolder.getInstance(project) - try { - holder.update { skipMetadataVersionCheck = true } - block() - } finally { - holder.update { skipMetadataVersionCheck = false } - } + module("usage").addLibrary(lib, kind = JSLibraryKind) + checkHighlightingInAllFiles() } private fun Module.setupKotlinFacet(configure: KotlinFacetConfiguration.() -> Unit) = apply { diff --git a/libraries/stdlib/js/build.gradle b/libraries/stdlib/js/build.gradle index 7e72733b25e..847e47e7fbc 100644 --- a/libraries/stdlib/js/build.gradle +++ b/libraries/stdlib/js/build.gradle @@ -176,8 +176,8 @@ task compileJs(type: JavaExec) { doFirst { args = [jsOutputFile, rootDir, "$jsSrcDir/wrapper.js"] + inputFiles.collect { it.path }.sort() + (compileBuiltinsKotlin2Js.outputs.files.collect { it.path }.sort() + - compileKotlin2Js.outputs.files.collect { it.path }.sort() + - compileExperimentalKotlin2Js.outputs.files.collect { it.path }.sort()).findAll { + compileKotlin2Js.outputs.files.collect { it.path }.sort() /* + + compileExperimentalKotlin2Js.outputs.files.collect { it.path }.sort() */).findAll { it.endsWith(".js") && !it.endsWith(".meta.js") } } @@ -223,9 +223,9 @@ task compileJs(type: JavaExec) { sourceMapFile.text = groovy.json.JsonOutput.toJson(sourceMap) - file(jsOutputMetaFile).text = file(compileKotlin2Js.outputFile.path.replaceAll('\\.js$', '.meta.js')).text + + file(jsOutputMetaFile).text = file(compileKotlin2Js.outputFile.path.replaceAll('\\.js$', '.meta.js')).text /* + file(compileExperimentalKotlin2Js.outputFile.path.replaceAll('\\.js$', '.meta.js')).text - .replaceFirst(experimentalJsModuleName, 'kotlin') + .replaceFirst(experimentalJsModuleName, 'kotlin') */ } } @@ -357,4 +357,4 @@ task runMocha(type: NodeTask, dependsOn: [testClasses, installMocha, ':kotlin-te } } -test.dependsOn runMocha \ No newline at end of file +test.dependsOn runMocha diff --git a/libraries/stdlib/experimental/kotlin/annotations/Experimental.kt b/libraries/stdlib/src/kotlin/annotations/Experimental.kt similarity index 77% rename from libraries/stdlib/experimental/kotlin/annotations/Experimental.kt rename to libraries/stdlib/src/kotlin/annotations/Experimental.kt index 0ed4de012eb..352900f4de2 100644 --- a/libraries/stdlib/experimental/kotlin/annotations/Experimental.kt +++ b/libraries/stdlib/src/kotlin/annotations/Experimental.kt @@ -8,16 +8,21 @@ package kotlin import kotlin.annotation.AnnotationRetention.BINARY import kotlin.annotation.AnnotationRetention.SOURCE import kotlin.annotation.AnnotationTarget.* +import kotlin.internal.RequireKotlin +import kotlin.internal.RequireKotlinVersionKind import kotlin.reflect.KClass /** * Signals that the annotated annotation class is a marker of an experimental API. Any declaration annotated with that marker is thus * considered an experimental declaration and its call sites should accept the experimental aspect of it either by using [UseExperimental], * or by being annotated with that marker themselves, effectively causing further propagation of that experimental aspect. + * + * This class is experimental itself and can only be used with the compiler argument `-Xuse-experimental=kotlin.Experimental`. */ @Target(ANNOTATION_CLASS) @Retention(BINARY) -@SinceKotlin("1.3") +@SinceKotlin("1.2") +@RequireKotlin("1.2.50", versionKind = RequireKotlinVersionKind.COMPILER_VERSION) @Suppress("ANNOTATION_CLASS_MEMBER") annotation class Experimental(val level: Level = Level.ERROR) { /** @@ -35,10 +40,13 @@ annotation class Experimental(val level: Level = Level.ERROR) { /** * Allows to use experimental API denoted by the given markers in the annotated file, declaration, or expression. * If a declaration is annotated with [UseExperimental], its usages are **not** required to opt-in to that experimental API. + * + * This class is experimental itself and can only be used with the compiler argument `-Xuse-experimental=kotlin.Experimental`. */ @Target(CLASS, PROPERTY, LOCAL_VARIABLE, VALUE_PARAMETER, CONSTRUCTOR, FUNCTION, PROPERTY_GETTER, PROPERTY_SETTER, EXPRESSION, FILE) @Retention(SOURCE) -@SinceKotlin("1.3") +@SinceKotlin("1.2") +@RequireKotlin("1.2.50", versionKind = RequireKotlinVersionKind.COMPILER_VERSION) annotation class UseExperimental( vararg val markerClass: KClass ) diff --git a/libraries/tools/binary-compatibility-validator/src/test/kotlin/org.jetbrains.kotlin.tools.tests/RuntimePublicAPITest.kt b/libraries/tools/binary-compatibility-validator/src/test/kotlin/org.jetbrains.kotlin.tools.tests/RuntimePublicAPITest.kt index c937829c0e1..2bc01de6306 100644 --- a/libraries/tools/binary-compatibility-validator/src/test/kotlin/org.jetbrains.kotlin.tools.tests/RuntimePublicAPITest.kt +++ b/libraries/tools/binary-compatibility-validator/src/test/kotlin/org.jetbrains.kotlin.tools.tests/RuntimePublicAPITest.kt @@ -35,7 +35,7 @@ class RuntimePublicAPITest { @Test fun kotlinStdlibRuntimeMerged() { snapshotAPIAndCompare( "../../stdlib/jvm/build/libs", "kotlin-stdlib", - listOf("../stdlib-declarations.json", "../stdlib-experimental-declarations.json"), + listOf("../stdlib-declarations.json"/*, "../stdlib-experimental-declarations.json"*/), listOf("kotlin.jvm.internal") ) }