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 fa984f7bda5..1b96033de00 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/resolve/checkers/ExperimentalUsageChecker.kt +++ b/compiler/frontend/src/org/jetbrains/kotlin/resolve/checkers/ExperimentalUsageChecker.kt @@ -217,29 +217,27 @@ class ExperimentalUsageChecker(project: Project) : CallChecker { val deprecationResolver = DeprecationResolver(LockBasedStorageManager(), languageVersionSettings, CoroutineCompatibilitySupport.ENABLED) + // Returns true if fqName refers to a valid experimental API marker. fun checkAnnotation(fqName: String): Boolean { val descriptor = module.resolveClassByFqName(FqName(fqName), NoLookupLocation.FOR_NON_TRACKED_SCOPE) - val experimentality = descriptor?.loadExperimentalityForMarkerAnnotation() - val message = when { - descriptor == null -> - "Experimental API marker $fqName is unresolved. Please make sure it's present in the module dependencies" - experimentality == null -> - "Class $fqName is not an experimental API marker annotation" - else -> { - for (deprecation in deprecationResolver.getDeprecations(descriptor)) { - val report = when (deprecation.deprecationLevel) { - DeprecationLevelValue.WARNING -> reportWarning - DeprecationLevelValue.ERROR, DeprecationLevelValue.HIDDEN -> reportError - } - report("Experimental API marker $fqName is deprecated" + deprecation.message?.let { ". $it" }.orEmpty()) - } - return true - } + if (descriptor == null) { + reportWarning("Experimental API marker $fqName is unresolved. Please make sure it's present in the module dependencies") + return false } - reportError(message) + if (descriptor.loadExperimentalityForMarkerAnnotation() == null) { + reportWarning("Class $fqName is not an experimental API marker annotation") + return false + } - return false + for (deprecation in deprecationResolver.getDeprecations(descriptor)) { + val report = when (deprecation.deprecationLevel) { + DeprecationLevelValue.WARNING -> reportWarning + DeprecationLevelValue.ERROR, DeprecationLevelValue.HIDDEN -> reportError + } + report("Experimental API marker $fqName is deprecated" + deprecation.message?.let { ". $it" }.orEmpty()) + } + return true } val validExperimental = languageVersionSettings.getFlag(AnalysisFlags.experimental).filter(::checkAnnotation) diff --git a/compiler/testData/cli/jvm/experimentalIsNotAnnotation.out b/compiler/testData/cli/jvm/experimentalIsNotAnnotation.out index acf9a443420..dccfb74f371 100644 --- a/compiler/testData/cli/jvm/experimentalIsNotAnnotation.out +++ b/compiler/testData/cli/jvm/experimentalIsNotAnnotation.out @@ -1,3 +1,3 @@ -error: class org.test.NotAnAnnotation1 is not an experimental API marker annotation -error: class org.test.NotAnAnnotation2 is not an experimental API marker annotation -COMPILATION_ERROR +warning: class org.test.NotAnAnnotation1 is not an experimental API marker annotation +warning: class org.test.NotAnAnnotation2 is not an experimental API marker annotation +OK diff --git a/compiler/testData/cli/jvm/experimentalIsNotMarker.out b/compiler/testData/cli/jvm/experimentalIsNotMarker.out index 6da2802a9b7..3e1f6f20f70 100644 --- a/compiler/testData/cli/jvm/experimentalIsNotMarker.out +++ b/compiler/testData/cli/jvm/experimentalIsNotMarker.out @@ -1,3 +1,3 @@ -error: class org.test.NotAMarker1 is not an experimental API marker annotation -error: class org.test.NotAMarker2 is not an experimental API marker annotation -COMPILATION_ERROR +warning: class org.test.NotAMarker1 is not an experimental API marker annotation +warning: class org.test.NotAMarker2 is not an experimental API marker annotation +OK diff --git a/compiler/testData/cli/jvm/experimentalUnresolved.out b/compiler/testData/cli/jvm/experimentalUnresolved.out index ee401fe996f..d58c03bb63e 100644 --- a/compiler/testData/cli/jvm/experimentalUnresolved.out +++ b/compiler/testData/cli/jvm/experimentalUnresolved.out @@ -1,4 +1,4 @@ -error: experimental API marker org.test.Unresolved2 is unresolved. Please make sure it's present in the module dependencies -error: experimental API marker org.test.Unresolved1 is unresolved. Please make sure it's present in the module dependencies -error: experimental API marker org.test.Unresolved3 is unresolved. Please make sure it's present in the module dependencies -COMPILATION_ERROR +warning: experimental API marker org.test.Unresolved2 is unresolved. Please make sure it's present in the module dependencies +warning: experimental API marker org.test.Unresolved1 is unresolved. Please make sure it's present in the module dependencies +warning: experimental API marker org.test.Unresolved3 is unresolved. Please make sure it's present in the module dependencies +OK