From a2da00eb493645f61e1947e862fe346b4357cecc Mon Sep 17 00:00:00 2001 From: Mikhail Zarechenskiy Date: Thu, 18 Jun 2020 18:26:49 +0300 Subject: [PATCH] Prohibit using DeprecatedSinceKotlin outside `kotlin` subpackage --- ...irOldFrontendDiagnosticsTestGenerated.java | 5 +++ .../jetbrains/kotlin/diagnostics/Errors.java | 1 + .../rendering/DefaultErrorMessages.java | 1 + .../DeprecatedSinceKotlinAnnotationChecker.kt | 11 ++++++ .../checkValuesAreParseableAsVersion.fir.kt | 2 ++ .../checkValuesAreParseableAsVersion.kt | 2 ++ .../checkValuesAreParseableAsVersion.txt | 12 ++++--- .../deprecatedSinceKotlinDeclaration.fir.kt | 2 ++ .../deprecatedSinceKotlinDeclaration.kt | 2 ++ .../deprecatedSinceKotlinDeclaration.txt | 35 +++++++++++-------- ...atedSinceKotlinOutsideKotlinPackage.fir.kt | 5 +++ ...precatedSinceKotlinOutsideKotlinPackage.kt | 5 +++ ...recatedSinceKotlinOutsideKotlinPackage.txt | 8 +++++ ...precatedSinceKotlinWithoutArguments.fir.kt | 2 ++ .../deprecatedSinceKotlinWithoutArguments.kt | 2 ++ .../deprecatedSinceKotlinWithoutArguments.txt | 6 ++-- .../deprecatedSinceKotlin/error.fir.kt | 2 ++ .../deprecated/deprecatedSinceKotlin/error.kt | 2 ++ .../deprecatedSinceKotlin/error.txt | 34 +++++++++--------- .../deprecatedSinceKotlin/hidden.fir.kt | 2 ++ .../deprecatedSinceKotlin/hidden.kt | 2 ++ .../deprecatedSinceKotlin/hidden.txt | 34 +++++++++--------- .../messageFromDeprecatedAnnotation.fir.kt | 2 ++ .../messageFromDeprecatedAnnotation.kt | 2 ++ .../messageFromDeprecatedAnnotation.txt | 6 ++-- .../deprecatedSinceKotlin/warning.fir.kt | 2 ++ .../deprecatedSinceKotlin/warning.kt | 2 ++ .../deprecatedSinceKotlin/warning.txt | 34 +++++++++--------- .../deprecatedFlag/deprecatedSinceKotlin.kt | 3 ++ .../checkers/DiagnosticsTestGenerated.java | 5 +++ .../DiagnosticsUsingJavacTestGenerated.java | 5 +++ .../deprecatedSinceKotlinAndReplaceWith.kt | 1 + ...precatedSinceKotlinAndReplaceWith.kt.after | 1 + 33 files changed, 168 insertions(+), 72 deletions(-) create mode 100644 compiler/testData/diagnostics/tests/deprecated/deprecatedSinceKotlin/deprecatedSinceKotlinOutsideKotlinPackage.fir.kt create mode 100644 compiler/testData/diagnostics/tests/deprecated/deprecatedSinceKotlin/deprecatedSinceKotlinOutsideKotlinPackage.kt create mode 100644 compiler/testData/diagnostics/tests/deprecated/deprecatedSinceKotlin/deprecatedSinceKotlinOutsideKotlinPackage.txt diff --git a/compiler/fir/analysis-tests/tests/org/jetbrains/kotlin/fir/FirOldFrontendDiagnosticsTestGenerated.java b/compiler/fir/analysis-tests/tests/org/jetbrains/kotlin/fir/FirOldFrontendDiagnosticsTestGenerated.java index 845c4d039f9..2058393a3cf 100644 --- a/compiler/fir/analysis-tests/tests/org/jetbrains/kotlin/fir/FirOldFrontendDiagnosticsTestGenerated.java +++ b/compiler/fir/analysis-tests/tests/org/jetbrains/kotlin/fir/FirOldFrontendDiagnosticsTestGenerated.java @@ -6667,6 +6667,11 @@ public class FirOldFrontendDiagnosticsTestGenerated extends AbstractFirOldFronte runTest("compiler/testData/diagnostics/tests/deprecated/deprecatedSinceKotlin/deprecatedSinceKotlinDeclaration.kt"); } + @TestMetadata("deprecatedSinceKotlinOutsideKotlinPackage.kt") + public void testDeprecatedSinceKotlinOutsideKotlinPackage() throws Exception { + runTest("compiler/testData/diagnostics/tests/deprecated/deprecatedSinceKotlin/deprecatedSinceKotlinOutsideKotlinPackage.kt"); + } + @TestMetadata("deprecatedSinceKotlinWithoutArguments.kt") public void testDeprecatedSinceKotlinWithoutArguments() throws Exception { runTest("compiler/testData/diagnostics/tests/deprecated/deprecatedSinceKotlin/deprecatedSinceKotlinWithoutArguments.kt"); diff --git a/compiler/frontend/src/org/jetbrains/kotlin/diagnostics/Errors.java b/compiler/frontend/src/org/jetbrains/kotlin/diagnostics/Errors.java index 41a81be3540..99fe86c562c 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/diagnostics/Errors.java +++ b/compiler/frontend/src/org/jetbrains/kotlin/diagnostics/Errors.java @@ -104,6 +104,7 @@ public interface Errors { DiagnosticFactory0 DEPRECATED_SINCE_KOTLIN_WITH_DEPRECATED_LEVEL = DiagnosticFactory0.create(ERROR); DiagnosticFactory0 DEPRECATED_SINCE_KOTLIN_WITH_UNORDERED_VERSIONS = DiagnosticFactory0.create(ERROR); DiagnosticFactory0 DEPRECATED_SINCE_KOTLIN_WITHOUT_ARGUMENTS = DiagnosticFactory0.create(ERROR); + DiagnosticFactory0 DEPRECATED_SINCE_KOTLIN_OUTSIDE_KOTLIN_SUBPACKAGE = DiagnosticFactory0.create(ERROR); DiagnosticFactory2 API_NOT_AVAILABLE = DiagnosticFactory2.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 3142ad54cc6..409967a2f39 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/diagnostics/rendering/DefaultErrorMessages.java +++ b/compiler/frontend/src/org/jetbrains/kotlin/diagnostics/rendering/DefaultErrorMessages.java @@ -381,6 +381,7 @@ public class DefaultErrorMessages { MAP.put(DEPRECATED_SINCE_KOTLIN_WITH_DEPRECATED_LEVEL, "DeprecatedSinceKotlin annotation can be used only with unspecified deprecation level of Deprecated annotation"); MAP.put(DEPRECATED_SINCE_KOTLIN_WITH_UNORDERED_VERSIONS, "Values of DeprecatedSinceKotlin annotation should be ordered so 'warningSince' <= 'errorSince' <= 'hiddenSince' if specified"); MAP.put(DEPRECATED_SINCE_KOTLIN_WITHOUT_ARGUMENTS, "DeprecatedSinceKotlin annotation should have at least one argument"); + MAP.put(DEPRECATED_SINCE_KOTLIN_OUTSIDE_KOTLIN_SUBPACKAGE, "DeprecatedSinceKotlin annotation cannot be used outside 'kotlin' subpackages"); MAP.put(API_NOT_AVAILABLE, "This declaration is only available since Kotlin {0} and cannot be used with the specified API version {1}", STRING, STRING); diff --git a/compiler/frontend/src/org/jetbrains/kotlin/resolve/checkers/DeprecatedSinceKotlinAnnotationChecker.kt b/compiler/frontend/src/org/jetbrains/kotlin/resolve/checkers/DeprecatedSinceKotlinAnnotationChecker.kt index 9577839dfb8..a168f91183c 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/resolve/checkers/DeprecatedSinceKotlinAnnotationChecker.kt +++ b/compiler/frontend/src/org/jetbrains/kotlin/resolve/checkers/DeprecatedSinceKotlinAnnotationChecker.kt @@ -12,12 +12,14 @@ import org.jetbrains.kotlin.descriptors.DeclarationDescriptor import org.jetbrains.kotlin.descriptors.annotations.AnnotationDescriptor import org.jetbrains.kotlin.diagnostics.Errors import org.jetbrains.kotlin.diagnostics.reportDiagnosticOnce +import org.jetbrains.kotlin.name.isSubpackageOf import org.jetbrains.kotlin.psi.KtAnnotationEntry import org.jetbrains.kotlin.psi.KtDeclaration import org.jetbrains.kotlin.resolve.RequireKotlinConstants import org.jetbrains.kotlin.resolve.annotations.argumentValue import org.jetbrains.kotlin.resolve.constants.StringValue import org.jetbrains.kotlin.resolve.deprecation.getSinceVersion +import org.jetbrains.kotlin.resolve.descriptorUtil.fqNameOrNull import org.jetbrains.kotlin.resolve.source.getPsi import org.jetbrains.kotlin.utils.addToStdlib.safeAs @@ -30,6 +32,15 @@ object DeprecatedSinceKotlinAnnotationChecker : DeclarationChecker { val deprecatedSinceAnnotationName = deprecatedSinceAnnotationPsi.typeReference ?: return + if (descriptor.fqNameOrNull()?.isSubpackageOf(KotlinBuiltIns.BUILT_INS_PACKAGE_FQ_NAME) == false) { + context.trace.report( + Errors.DEPRECATED_SINCE_KOTLIN_OUTSIDE_KOTLIN_SUBPACKAGE.on( + deprecatedSinceAnnotationName + ) + ) + return + } + if (deprecatedAnnotation == null) { context.trace.report( Errors.DEPRECATED_SINCE_KOTLIN_WITHOUT_DEPRECATED.on( diff --git a/compiler/testData/diagnostics/tests/deprecated/deprecatedSinceKotlin/checkValuesAreParseableAsVersion.fir.kt b/compiler/testData/diagnostics/tests/deprecated/deprecatedSinceKotlin/checkValuesAreParseableAsVersion.fir.kt index 1b7d1ff6d12..b68c5e38114 100644 --- a/compiler/testData/diagnostics/tests/deprecated/deprecatedSinceKotlin/checkValuesAreParseableAsVersion.fir.kt +++ b/compiler/testData/diagnostics/tests/deprecated/deprecatedSinceKotlin/checkValuesAreParseableAsVersion.fir.kt @@ -1,3 +1,5 @@ +package kotlin + @Deprecated("") @DeprecatedSinceKotlin("", errorSince = "1.0") fun test1() {} diff --git a/compiler/testData/diagnostics/tests/deprecated/deprecatedSinceKotlin/checkValuesAreParseableAsVersion.kt b/compiler/testData/diagnostics/tests/deprecated/deprecatedSinceKotlin/checkValuesAreParseableAsVersion.kt index 2224113d20f..24f3e5a1fdb 100644 --- a/compiler/testData/diagnostics/tests/deprecated/deprecatedSinceKotlin/checkValuesAreParseableAsVersion.kt +++ b/compiler/testData/diagnostics/tests/deprecated/deprecatedSinceKotlin/checkValuesAreParseableAsVersion.kt @@ -1,3 +1,5 @@ +package kotlin + @Deprecated("") @DeprecatedSinceKotlin("", errorSince = "1.0") fun test1() {} diff --git a/compiler/testData/diagnostics/tests/deprecated/deprecatedSinceKotlin/checkValuesAreParseableAsVersion.txt b/compiler/testData/diagnostics/tests/deprecated/deprecatedSinceKotlin/checkValuesAreParseableAsVersion.txt index f900dce0166..2bc4f4a7b22 100644 --- a/compiler/testData/diagnostics/tests/deprecated/deprecatedSinceKotlin/checkValuesAreParseableAsVersion.txt +++ b/compiler/testData/diagnostics/tests/deprecated/deprecatedSinceKotlin/checkValuesAreParseableAsVersion.txt @@ -1,7 +1,9 @@ package -@kotlin.Deprecated(message = "") @kotlin.DeprecatedSinceKotlin(errorSince = "1.0", warningSince = "") public fun test1(): kotlin.Unit -@kotlin.Deprecated(message = "") @kotlin.DeprecatedSinceKotlin(warningSince = "") public fun test2(): kotlin.Unit -@kotlin.Deprecated(message = "") @kotlin.DeprecatedSinceKotlin(errorSince = "", hiddenSince = "", warningSince = "") public fun test3(): kotlin.Unit -@kotlin.Deprecated(message = "") @kotlin.DeprecatedSinceKotlin(warningSince = "1.4-M2") public fun test4(): kotlin.Unit -@kotlin.Deprecated(message = "") @kotlin.DeprecatedSinceKotlin(warningSince = "1.3.70") public fun test5(): kotlin.Unit +package kotlin { + @kotlin.Deprecated(message = "") @kotlin.DeprecatedSinceKotlin(errorSince = "1.0", warningSince = "") public fun test1(): kotlin.Unit + @kotlin.Deprecated(message = "") @kotlin.DeprecatedSinceKotlin(warningSince = "") public fun test2(): kotlin.Unit + @kotlin.Deprecated(message = "") @kotlin.DeprecatedSinceKotlin(errorSince = "", hiddenSince = "", warningSince = "") public fun test3(): kotlin.Unit + @kotlin.Deprecated(message = "") @kotlin.DeprecatedSinceKotlin(warningSince = "1.4-M2") public fun test4(): kotlin.Unit + @kotlin.Deprecated(message = "") @kotlin.DeprecatedSinceKotlin(warningSince = "1.3.70") public fun test5(): kotlin.Unit +} diff --git a/compiler/testData/diagnostics/tests/deprecated/deprecatedSinceKotlin/deprecatedSinceKotlinDeclaration.fir.kt b/compiler/testData/diagnostics/tests/deprecated/deprecatedSinceKotlin/deprecatedSinceKotlinDeclaration.fir.kt index ba5f1b9383e..9f9ead10cba 100644 --- a/compiler/testData/diagnostics/tests/deprecated/deprecatedSinceKotlin/deprecatedSinceKotlinDeclaration.fir.kt +++ b/compiler/testData/diagnostics/tests/deprecated/deprecatedSinceKotlin/deprecatedSinceKotlinDeclaration.fir.kt @@ -1,3 +1,5 @@ +package kotlin.sub + @Deprecated("", ReplaceWith("")) @DeprecatedSinceKotlin(warningSince = "1.0", errorSince = "1.1", hiddenSince = "1.2") fun good() {} diff --git a/compiler/testData/diagnostics/tests/deprecated/deprecatedSinceKotlin/deprecatedSinceKotlinDeclaration.kt b/compiler/testData/diagnostics/tests/deprecated/deprecatedSinceKotlin/deprecatedSinceKotlinDeclaration.kt index 7c0e43d8094..bf687e49b2a 100644 --- a/compiler/testData/diagnostics/tests/deprecated/deprecatedSinceKotlin/deprecatedSinceKotlinDeclaration.kt +++ b/compiler/testData/diagnostics/tests/deprecated/deprecatedSinceKotlin/deprecatedSinceKotlinDeclaration.kt @@ -1,3 +1,5 @@ +package kotlin.sub + @Deprecated("", ReplaceWith("")) @DeprecatedSinceKotlin(warningSince = "1.0", errorSince = "1.1", hiddenSince = "1.2") fun good() {} diff --git a/compiler/testData/diagnostics/tests/deprecated/deprecatedSinceKotlin/deprecatedSinceKotlinDeclaration.txt b/compiler/testData/diagnostics/tests/deprecated/deprecatedSinceKotlin/deprecatedSinceKotlinDeclaration.txt index 896c37046a0..65094b8288e 100644 --- a/compiler/testData/diagnostics/tests/deprecated/deprecatedSinceKotlin/deprecatedSinceKotlinDeclaration.txt +++ b/compiler/testData/diagnostics/tests/deprecated/deprecatedSinceKotlin/deprecatedSinceKotlinDeclaration.txt @@ -1,19 +1,24 @@ package -@kotlin.Deprecated(message = "") @kotlin.DeprecatedSinceKotlin(errorSince = "1.1", hiddenSince = "1.1", warningSince = "1.2") public fun fooDefault(): kotlin.Unit -@kotlin.Deprecated(level = DeprecationLevel.WARNING, message = "", replaceWith = kotlin.ReplaceWith(expression = "", imports = {})) @kotlin.DeprecatedSinceKotlin public fun fooDefaultWarning(): kotlin.Unit -@kotlin.Deprecated(message = "") @kotlin.DeprecatedSinceKotlin(errorSince = "1.1", hiddenSince = "1.1", warningSince = "1.1") public fun fooEqual(): kotlin.Unit -@kotlin.Deprecated(level = DeprecationLevel.ERROR, message = "") @kotlin.DeprecatedSinceKotlin public fun fooError(): kotlin.Unit -@kotlin.Deprecated(message = "") @kotlin.DeprecatedSinceKotlin(errorSince = "1.3", hiddenSince = "1.2", warningSince = "1.1") public fun fooErrorIsGreater(): kotlin.Unit -@kotlin.Deprecated(level = DeprecationLevel.HIDDEN, message = "") @kotlin.DeprecatedSinceKotlin public fun fooHidden(): kotlin.Unit -@kotlin.Deprecated(level = DeprecationLevel.WARNING, message = "") @kotlin.DeprecatedSinceKotlin public fun fooWarning(): kotlin.Unit -@kotlin.Deprecated(message = "") @kotlin.DeprecatedSinceKotlin(errorSince = "1.0", warningSince = "1.1") public fun fooWarningIsGreater1(): kotlin.Unit -@kotlin.Deprecated(message = "") @kotlin.DeprecatedSinceKotlin(hiddenSince = "1.0", warningSince = "1.1") public fun fooWarningIsGreater2(): kotlin.Unit -@kotlin.Deprecated(message = "", replaceWith = kotlin.ReplaceWith(expression = "", imports = {})) @kotlin.DeprecatedSinceKotlin(errorSince = "1.1", hiddenSince = "1.2", warningSince = "1.0") public fun good(): kotlin.Unit +package kotlin { -@kotlin.DeprecatedSinceKotlin public final class Clazz { - public constructor Clazz() - 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 + package kotlin.sub { + @kotlin.Deprecated(message = "") @kotlin.DeprecatedSinceKotlin(errorSince = "1.1", hiddenSince = "1.1", warningSince = "1.2") public fun fooDefault(): kotlin.Unit + @kotlin.Deprecated(level = DeprecationLevel.WARNING, message = "", replaceWith = kotlin.ReplaceWith(expression = "", imports = {})) @kotlin.DeprecatedSinceKotlin public fun fooDefaultWarning(): kotlin.Unit + @kotlin.Deprecated(message = "") @kotlin.DeprecatedSinceKotlin(errorSince = "1.1", hiddenSince = "1.1", warningSince = "1.1") public fun fooEqual(): kotlin.Unit + @kotlin.Deprecated(level = DeprecationLevel.ERROR, message = "") @kotlin.DeprecatedSinceKotlin public fun fooError(): kotlin.Unit + @kotlin.Deprecated(message = "") @kotlin.DeprecatedSinceKotlin(errorSince = "1.3", hiddenSince = "1.2", warningSince = "1.1") public fun fooErrorIsGreater(): kotlin.Unit + @kotlin.Deprecated(level = DeprecationLevel.HIDDEN, message = "") @kotlin.DeprecatedSinceKotlin public fun fooHidden(): kotlin.Unit + @kotlin.Deprecated(level = DeprecationLevel.WARNING, message = "") @kotlin.DeprecatedSinceKotlin public fun fooWarning(): kotlin.Unit + @kotlin.Deprecated(message = "") @kotlin.DeprecatedSinceKotlin(errorSince = "1.0", warningSince = "1.1") public fun fooWarningIsGreater1(): kotlin.Unit + @kotlin.Deprecated(message = "") @kotlin.DeprecatedSinceKotlin(hiddenSince = "1.0", warningSince = "1.1") public fun fooWarningIsGreater2(): kotlin.Unit + @kotlin.Deprecated(message = "", replaceWith = kotlin.ReplaceWith(expression = "", imports = {})) @kotlin.DeprecatedSinceKotlin(errorSince = "1.1", hiddenSince = "1.2", warningSince = "1.0") public fun good(): kotlin.Unit + + @kotlin.DeprecatedSinceKotlin public final class Clazz { + public constructor Clazz() + 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/tests/deprecated/deprecatedSinceKotlin/deprecatedSinceKotlinOutsideKotlinPackage.fir.kt b/compiler/testData/diagnostics/tests/deprecated/deprecatedSinceKotlin/deprecatedSinceKotlinOutsideKotlinPackage.fir.kt new file mode 100644 index 00000000000..3e7f2c987bb --- /dev/null +++ b/compiler/testData/diagnostics/tests/deprecated/deprecatedSinceKotlin/deprecatedSinceKotlinOutsideKotlinPackage.fir.kt @@ -0,0 +1,5 @@ +package foo.bar + +@Deprecated("") +@DeprecatedSinceKotlin("1.3") +fun test() {} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/deprecated/deprecatedSinceKotlin/deprecatedSinceKotlinOutsideKotlinPackage.kt b/compiler/testData/diagnostics/tests/deprecated/deprecatedSinceKotlin/deprecatedSinceKotlinOutsideKotlinPackage.kt new file mode 100644 index 00000000000..77dcdc69c5e --- /dev/null +++ b/compiler/testData/diagnostics/tests/deprecated/deprecatedSinceKotlin/deprecatedSinceKotlinOutsideKotlinPackage.kt @@ -0,0 +1,5 @@ +package foo.bar + +@Deprecated("") +@DeprecatedSinceKotlin("1.3") +fun test() {} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/deprecated/deprecatedSinceKotlin/deprecatedSinceKotlinOutsideKotlinPackage.txt b/compiler/testData/diagnostics/tests/deprecated/deprecatedSinceKotlin/deprecatedSinceKotlinOutsideKotlinPackage.txt new file mode 100644 index 00000000000..996d1a760bf --- /dev/null +++ b/compiler/testData/diagnostics/tests/deprecated/deprecatedSinceKotlin/deprecatedSinceKotlinOutsideKotlinPackage.txt @@ -0,0 +1,8 @@ +package + +package foo { + + package foo.bar { + @kotlin.Deprecated(message = "") @kotlin.DeprecatedSinceKotlin(warningSince = "1.3") public fun test(): kotlin.Unit + } +} diff --git a/compiler/testData/diagnostics/tests/deprecated/deprecatedSinceKotlin/deprecatedSinceKotlinWithoutArguments.fir.kt b/compiler/testData/diagnostics/tests/deprecated/deprecatedSinceKotlin/deprecatedSinceKotlinWithoutArguments.fir.kt index 3364cebaad4..46ae902a5b7 100644 --- a/compiler/testData/diagnostics/tests/deprecated/deprecatedSinceKotlin/deprecatedSinceKotlinWithoutArguments.fir.kt +++ b/compiler/testData/diagnostics/tests/deprecated/deprecatedSinceKotlin/deprecatedSinceKotlinWithoutArguments.fir.kt @@ -1,3 +1,5 @@ +package kotlin + @Deprecated("") @DeprecatedSinceKotlin fun foo() {} diff --git a/compiler/testData/diagnostics/tests/deprecated/deprecatedSinceKotlin/deprecatedSinceKotlinWithoutArguments.kt b/compiler/testData/diagnostics/tests/deprecated/deprecatedSinceKotlin/deprecatedSinceKotlinWithoutArguments.kt index b99ee781fa6..293aded9734 100644 --- a/compiler/testData/diagnostics/tests/deprecated/deprecatedSinceKotlin/deprecatedSinceKotlinWithoutArguments.kt +++ b/compiler/testData/diagnostics/tests/deprecated/deprecatedSinceKotlin/deprecatedSinceKotlinWithoutArguments.kt @@ -1,3 +1,5 @@ +package kotlin + @Deprecated("") @DeprecatedSinceKotlin fun foo() {} diff --git a/compiler/testData/diagnostics/tests/deprecated/deprecatedSinceKotlin/deprecatedSinceKotlinWithoutArguments.txt b/compiler/testData/diagnostics/tests/deprecated/deprecatedSinceKotlin/deprecatedSinceKotlinWithoutArguments.txt index 28645e720ac..92170a7c893 100644 --- a/compiler/testData/diagnostics/tests/deprecated/deprecatedSinceKotlin/deprecatedSinceKotlinWithoutArguments.txt +++ b/compiler/testData/diagnostics/tests/deprecated/deprecatedSinceKotlin/deprecatedSinceKotlinWithoutArguments.txt @@ -1,4 +1,6 @@ package -@kotlin.Deprecated(message = "") @kotlin.DeprecatedSinceKotlin public fun foo(): kotlin.Unit -public fun test(): kotlin.Unit +package kotlin { + @kotlin.Deprecated(message = "") @kotlin.DeprecatedSinceKotlin public fun foo(): kotlin.Unit + public fun test(): kotlin.Unit +} diff --git a/compiler/testData/diagnostics/tests/deprecated/deprecatedSinceKotlin/error.fir.kt b/compiler/testData/diagnostics/tests/deprecated/deprecatedSinceKotlin/error.fir.kt index 30c6c574f53..a9117b7271a 100644 --- a/compiler/testData/diagnostics/tests/deprecated/deprecatedSinceKotlin/error.fir.kt +++ b/compiler/testData/diagnostics/tests/deprecated/deprecatedSinceKotlin/error.fir.kt @@ -1,5 +1,7 @@ // !API_VERSION: 1.4 +package kotlin + @Deprecated("") @DeprecatedSinceKotlin(errorSince = "1.4") class ClassCur diff --git a/compiler/testData/diagnostics/tests/deprecated/deprecatedSinceKotlin/error.kt b/compiler/testData/diagnostics/tests/deprecated/deprecatedSinceKotlin/error.kt index 354a976d664..f7ecae7a800 100644 --- a/compiler/testData/diagnostics/tests/deprecated/deprecatedSinceKotlin/error.kt +++ b/compiler/testData/diagnostics/tests/deprecated/deprecatedSinceKotlin/error.kt @@ -1,5 +1,7 @@ // !API_VERSION: 1.4 +package kotlin + @Deprecated("") @DeprecatedSinceKotlin(errorSince = "1.4") class ClassCur diff --git a/compiler/testData/diagnostics/tests/deprecated/deprecatedSinceKotlin/error.txt b/compiler/testData/diagnostics/tests/deprecated/deprecatedSinceKotlin/error.txt index 6df402f9058..fb2c150b8a7 100644 --- a/compiler/testData/diagnostics/tests/deprecated/deprecatedSinceKotlin/error.txt +++ b/compiler/testData/diagnostics/tests/deprecated/deprecatedSinceKotlin/error.txt @@ -1,21 +1,23 @@ package -@kotlin.Deprecated(message = "") @kotlin.DeprecatedSinceKotlin(errorSince = "1.4") public val valCur: kotlin.Unit -@kotlin.Deprecated(message = "") @kotlin.DeprecatedSinceKotlin(errorSince = "1.5") public val valNext: kotlin.Unit -@kotlin.Deprecated(message = "") @kotlin.DeprecatedSinceKotlin(errorSince = "1.4") public fun funCur(): kotlin.Unit -@kotlin.Deprecated(message = "") @kotlin.DeprecatedSinceKotlin(errorSince = "1.5") public fun funNext(): kotlin.Unit -public fun usage(): kotlin.Unit +package kotlin { + @kotlin.Deprecated(message = "") @kotlin.DeprecatedSinceKotlin(errorSince = "1.4") public val valCur: kotlin.Unit + @kotlin.Deprecated(message = "") @kotlin.DeprecatedSinceKotlin(errorSince = "1.5") public val valNext: kotlin.Unit + @kotlin.Deprecated(message = "") @kotlin.DeprecatedSinceKotlin(errorSince = "1.4") public fun funCur(): kotlin.Unit + @kotlin.Deprecated(message = "") @kotlin.DeprecatedSinceKotlin(errorSince = "1.5") public fun funNext(): kotlin.Unit + public fun usage(): kotlin.Unit -@kotlin.Deprecated(message = "") @kotlin.DeprecatedSinceKotlin(errorSince = "1.4") public final class ClassCur { - public constructor ClassCur() - 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 -} + @kotlin.Deprecated(message = "") @kotlin.DeprecatedSinceKotlin(errorSince = "1.4") public final class ClassCur { + public constructor ClassCur() + 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 + } -@kotlin.Deprecated(message = "") @kotlin.DeprecatedSinceKotlin(errorSince = "1.5") public final class ClassNext { - public constructor ClassNext() - 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 + @kotlin.Deprecated(message = "") @kotlin.DeprecatedSinceKotlin(errorSince = "1.5") public final class ClassNext { + public constructor ClassNext() + 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/tests/deprecated/deprecatedSinceKotlin/hidden.fir.kt b/compiler/testData/diagnostics/tests/deprecated/deprecatedSinceKotlin/hidden.fir.kt index 04d74c9fcc0..d240d8e439b 100644 --- a/compiler/testData/diagnostics/tests/deprecated/deprecatedSinceKotlin/hidden.fir.kt +++ b/compiler/testData/diagnostics/tests/deprecated/deprecatedSinceKotlin/hidden.fir.kt @@ -1,5 +1,7 @@ // !API_VERSION: 1.4 +package kotlin + @Deprecated("") @DeprecatedSinceKotlin(hiddenSince = "1.4") class ClassCur diff --git a/compiler/testData/diagnostics/tests/deprecated/deprecatedSinceKotlin/hidden.kt b/compiler/testData/diagnostics/tests/deprecated/deprecatedSinceKotlin/hidden.kt index 53a3ef766d4..3c06b91063a 100644 --- a/compiler/testData/diagnostics/tests/deprecated/deprecatedSinceKotlin/hidden.kt +++ b/compiler/testData/diagnostics/tests/deprecated/deprecatedSinceKotlin/hidden.kt @@ -1,5 +1,7 @@ // !API_VERSION: 1.4 +package kotlin + @Deprecated("") @DeprecatedSinceKotlin(hiddenSince = "1.4") class ClassCur diff --git a/compiler/testData/diagnostics/tests/deprecated/deprecatedSinceKotlin/hidden.txt b/compiler/testData/diagnostics/tests/deprecated/deprecatedSinceKotlin/hidden.txt index 210967a42de..165299b9561 100644 --- a/compiler/testData/diagnostics/tests/deprecated/deprecatedSinceKotlin/hidden.txt +++ b/compiler/testData/diagnostics/tests/deprecated/deprecatedSinceKotlin/hidden.txt @@ -1,21 +1,23 @@ package -@kotlin.Deprecated(message = "") @kotlin.DeprecatedSinceKotlin(hiddenSince = "1.4") public val valCur: kotlin.Unit -@kotlin.Deprecated(message = "") @kotlin.DeprecatedSinceKotlin(hiddenSince = "1.5") public val valNext: kotlin.Unit -@kotlin.Deprecated(message = "") @kotlin.DeprecatedSinceKotlin(hiddenSince = "1.4") public fun funCur(): kotlin.Unit -@kotlin.Deprecated(message = "") @kotlin.DeprecatedSinceKotlin(hiddenSince = "1.5") public fun funNext(): kotlin.Unit -public fun usage(): kotlin.Unit +package kotlin { + @kotlin.Deprecated(message = "") @kotlin.DeprecatedSinceKotlin(hiddenSince = "1.4") public val valCur: kotlin.Unit + @kotlin.Deprecated(message = "") @kotlin.DeprecatedSinceKotlin(hiddenSince = "1.5") public val valNext: kotlin.Unit + @kotlin.Deprecated(message = "") @kotlin.DeprecatedSinceKotlin(hiddenSince = "1.4") public fun funCur(): kotlin.Unit + @kotlin.Deprecated(message = "") @kotlin.DeprecatedSinceKotlin(hiddenSince = "1.5") public fun funNext(): kotlin.Unit + public fun usage(): kotlin.Unit -@kotlin.Deprecated(message = "") @kotlin.DeprecatedSinceKotlin(hiddenSince = "1.4") public final class ClassCur { - public constructor ClassCur() - 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 -} + @kotlin.Deprecated(message = "") @kotlin.DeprecatedSinceKotlin(hiddenSince = "1.4") public final class ClassCur { + public constructor ClassCur() + 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 + } -@kotlin.Deprecated(message = "") @kotlin.DeprecatedSinceKotlin(hiddenSince = "1.5") public final class ClassNext { - public constructor ClassNext() - 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 + @kotlin.Deprecated(message = "") @kotlin.DeprecatedSinceKotlin(hiddenSince = "1.5") public final class ClassNext { + public constructor ClassNext() + 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/tests/deprecated/deprecatedSinceKotlin/messageFromDeprecatedAnnotation.fir.kt b/compiler/testData/diagnostics/tests/deprecated/deprecatedSinceKotlin/messageFromDeprecatedAnnotation.fir.kt index fa0d2bfe666..c7c4185d33f 100644 --- a/compiler/testData/diagnostics/tests/deprecated/deprecatedSinceKotlin/messageFromDeprecatedAnnotation.fir.kt +++ b/compiler/testData/diagnostics/tests/deprecated/deprecatedSinceKotlin/messageFromDeprecatedAnnotation.fir.kt @@ -1,3 +1,5 @@ +package kotlin + @Deprecated("foo test") @DeprecatedSinceKotlin(warningSince = "1.0") fun foo() {} diff --git a/compiler/testData/diagnostics/tests/deprecated/deprecatedSinceKotlin/messageFromDeprecatedAnnotation.kt b/compiler/testData/diagnostics/tests/deprecated/deprecatedSinceKotlin/messageFromDeprecatedAnnotation.kt index a36a27dc8e4..50900ce316a 100644 --- a/compiler/testData/diagnostics/tests/deprecated/deprecatedSinceKotlin/messageFromDeprecatedAnnotation.kt +++ b/compiler/testData/diagnostics/tests/deprecated/deprecatedSinceKotlin/messageFromDeprecatedAnnotation.kt @@ -1,3 +1,5 @@ +package kotlin + @Deprecated("foo test") @DeprecatedSinceKotlin(warningSince = "1.0") fun foo() {} diff --git a/compiler/testData/diagnostics/tests/deprecated/deprecatedSinceKotlin/messageFromDeprecatedAnnotation.txt b/compiler/testData/diagnostics/tests/deprecated/deprecatedSinceKotlin/messageFromDeprecatedAnnotation.txt index 2923acffd94..c5aa33fb929 100644 --- a/compiler/testData/diagnostics/tests/deprecated/deprecatedSinceKotlin/messageFromDeprecatedAnnotation.txt +++ b/compiler/testData/diagnostics/tests/deprecated/deprecatedSinceKotlin/messageFromDeprecatedAnnotation.txt @@ -1,4 +1,6 @@ package -@kotlin.Deprecated(message = "foo test") @kotlin.DeprecatedSinceKotlin(warningSince = "1.0") public fun foo(): kotlin.Unit -public fun test(): kotlin.Unit +package kotlin { + @kotlin.Deprecated(message = "foo test") @kotlin.DeprecatedSinceKotlin(warningSince = "1.0") public fun foo(): kotlin.Unit + public fun test(): kotlin.Unit +} diff --git a/compiler/testData/diagnostics/tests/deprecated/deprecatedSinceKotlin/warning.fir.kt b/compiler/testData/diagnostics/tests/deprecated/deprecatedSinceKotlin/warning.fir.kt index 1015b86c8c7..8a4c5b6dead 100644 --- a/compiler/testData/diagnostics/tests/deprecated/deprecatedSinceKotlin/warning.fir.kt +++ b/compiler/testData/diagnostics/tests/deprecated/deprecatedSinceKotlin/warning.fir.kt @@ -1,5 +1,7 @@ // !API_VERSION: 1.4 +package kotlin + @Deprecated("") @DeprecatedSinceKotlin(warningSince = "1.4") class ClassCur diff --git a/compiler/testData/diagnostics/tests/deprecated/deprecatedSinceKotlin/warning.kt b/compiler/testData/diagnostics/tests/deprecated/deprecatedSinceKotlin/warning.kt index 5cc73657fa1..48a4d370ffc 100644 --- a/compiler/testData/diagnostics/tests/deprecated/deprecatedSinceKotlin/warning.kt +++ b/compiler/testData/diagnostics/tests/deprecated/deprecatedSinceKotlin/warning.kt @@ -1,5 +1,7 @@ // !API_VERSION: 1.4 +package kotlin + @Deprecated("") @DeprecatedSinceKotlin(warningSince = "1.4") class ClassCur diff --git a/compiler/testData/diagnostics/tests/deprecated/deprecatedSinceKotlin/warning.txt b/compiler/testData/diagnostics/tests/deprecated/deprecatedSinceKotlin/warning.txt index e5e4b5beccd..161a44bfc7c 100644 --- a/compiler/testData/diagnostics/tests/deprecated/deprecatedSinceKotlin/warning.txt +++ b/compiler/testData/diagnostics/tests/deprecated/deprecatedSinceKotlin/warning.txt @@ -1,21 +1,23 @@ package -@kotlin.Deprecated(message = "") @kotlin.DeprecatedSinceKotlin(warningSince = "1.4") public val valCur: kotlin.Unit -@kotlin.Deprecated(message = "") @kotlin.DeprecatedSinceKotlin(warningSince = "1.5") public val valNext: kotlin.Unit -@kotlin.Deprecated(message = "") @kotlin.DeprecatedSinceKotlin(warningSince = "1.4") public fun funCur(): kotlin.Unit -@kotlin.Deprecated(message = "") @kotlin.DeprecatedSinceKotlin(warningSince = "1.5") public fun funNext(): kotlin.Unit -public fun usage(): kotlin.Unit +package kotlin { + @kotlin.Deprecated(message = "") @kotlin.DeprecatedSinceKotlin(warningSince = "1.4") public val valCur: kotlin.Unit + @kotlin.Deprecated(message = "") @kotlin.DeprecatedSinceKotlin(warningSince = "1.5") public val valNext: kotlin.Unit + @kotlin.Deprecated(message = "") @kotlin.DeprecatedSinceKotlin(warningSince = "1.4") public fun funCur(): kotlin.Unit + @kotlin.Deprecated(message = "") @kotlin.DeprecatedSinceKotlin(warningSince = "1.5") public fun funNext(): kotlin.Unit + public fun usage(): kotlin.Unit -@kotlin.Deprecated(message = "") @kotlin.DeprecatedSinceKotlin(warningSince = "1.4") public final class ClassCur { - public constructor ClassCur() - 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 -} + @kotlin.Deprecated(message = "") @kotlin.DeprecatedSinceKotlin(warningSince = "1.4") public final class ClassCur { + public constructor ClassCur() + 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 + } -@kotlin.Deprecated(message = "") @kotlin.DeprecatedSinceKotlin(warningSince = "1.5") public final class ClassNext { - public constructor ClassNext() - 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 + @kotlin.Deprecated(message = "") @kotlin.DeprecatedSinceKotlin(warningSince = "1.5") public final class ClassNext { + public constructor ClassNext() + 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/writeFlags/function/deprecatedFlag/deprecatedSinceKotlin.kt b/compiler/testData/writeFlags/function/deprecatedFlag/deprecatedSinceKotlin.kt index f5c0a38e2d8..a9e17231cda 100644 --- a/compiler/testData/writeFlags/function/deprecatedFlag/deprecatedSinceKotlin.kt +++ b/compiler/testData/writeFlags/function/deprecatedFlag/deprecatedSinceKotlin.kt @@ -1,11 +1,14 @@ +@Suppress("DEPRECATED_SINCE_KOTLIN_OUTSIDE_KOTLIN_SUBPACKAGE") @Deprecated("") @DeprecatedSinceKotlin(warningSince = "1.0") fun test1() {} +@Suppress("DEPRECATED_SINCE_KOTLIN_OUTSIDE_KOTLIN_SUBPACKAGE") @Deprecated("") @DeprecatedSinceKotlin(warningSince = "1.9") fun test2() {} +@Suppress("DEPRECATED_SINCE_KOTLIN_OUTSIDE_KOTLIN_SUBPACKAGE") @Deprecated("") @DeprecatedSinceKotlin fun test3() {} diff --git a/compiler/tests/org/jetbrains/kotlin/checkers/DiagnosticsTestGenerated.java b/compiler/tests/org/jetbrains/kotlin/checkers/DiagnosticsTestGenerated.java index ba0db1941cd..f020c7ffa5b 100644 --- a/compiler/tests/org/jetbrains/kotlin/checkers/DiagnosticsTestGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/checkers/DiagnosticsTestGenerated.java @@ -6674,6 +6674,11 @@ public class DiagnosticsTestGenerated extends AbstractDiagnosticsTestWithFirVali runTest("compiler/testData/diagnostics/tests/deprecated/deprecatedSinceKotlin/deprecatedSinceKotlinDeclaration.kt"); } + @TestMetadata("deprecatedSinceKotlinOutsideKotlinPackage.kt") + public void testDeprecatedSinceKotlinOutsideKotlinPackage() throws Exception { + runTest("compiler/testData/diagnostics/tests/deprecated/deprecatedSinceKotlin/deprecatedSinceKotlinOutsideKotlinPackage.kt"); + } + @TestMetadata("deprecatedSinceKotlinWithoutArguments.kt") public void testDeprecatedSinceKotlinWithoutArguments() throws Exception { runTest("compiler/testData/diagnostics/tests/deprecated/deprecatedSinceKotlin/deprecatedSinceKotlinWithoutArguments.kt"); diff --git a/compiler/tests/org/jetbrains/kotlin/checkers/javac/DiagnosticsUsingJavacTestGenerated.java b/compiler/tests/org/jetbrains/kotlin/checkers/javac/DiagnosticsUsingJavacTestGenerated.java index befd4299afb..f54e8945748 100644 --- a/compiler/tests/org/jetbrains/kotlin/checkers/javac/DiagnosticsUsingJavacTestGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/checkers/javac/DiagnosticsUsingJavacTestGenerated.java @@ -6669,6 +6669,11 @@ public class DiagnosticsUsingJavacTestGenerated extends AbstractDiagnosticsUsing runTest("compiler/testData/diagnostics/tests/deprecated/deprecatedSinceKotlin/deprecatedSinceKotlinDeclaration.kt"); } + @TestMetadata("deprecatedSinceKotlinOutsideKotlinPackage.kt") + public void testDeprecatedSinceKotlinOutsideKotlinPackage() throws Exception { + runTest("compiler/testData/diagnostics/tests/deprecated/deprecatedSinceKotlin/deprecatedSinceKotlinOutsideKotlinPackage.kt"); + } + @TestMetadata("deprecatedSinceKotlinWithoutArguments.kt") public void testDeprecatedSinceKotlinWithoutArguments() throws Exception { runTest("compiler/testData/diagnostics/tests/deprecated/deprecatedSinceKotlin/deprecatedSinceKotlinWithoutArguments.kt"); diff --git a/idea/testData/quickfix/deprecatedSymbolUsage/deprecatedSinceKotlinAndReplaceWith.kt b/idea/testData/quickfix/deprecatedSymbolUsage/deprecatedSinceKotlinAndReplaceWith.kt index e4880e3735f..58738ba739a 100644 --- a/idea/testData/quickfix/deprecatedSymbolUsage/deprecatedSinceKotlinAndReplaceWith.kt +++ b/idea/testData/quickfix/deprecatedSymbolUsage/deprecatedSinceKotlinAndReplaceWith.kt @@ -1,5 +1,6 @@ // "Replace with 'newFun()'" "true" +@Suppress("DEPRECATED_SINCE_KOTLIN_OUTSIDE_KOTLIN_SUBPACKAGE") @Deprecated("", ReplaceWith("newFun()")) @DeprecatedSinceKotlin(warningSince = "1.0") fun oldFun() { diff --git a/idea/testData/quickfix/deprecatedSymbolUsage/deprecatedSinceKotlinAndReplaceWith.kt.after b/idea/testData/quickfix/deprecatedSymbolUsage/deprecatedSinceKotlinAndReplaceWith.kt.after index c9b8e8d041d..92957f67c2c 100644 --- a/idea/testData/quickfix/deprecatedSymbolUsage/deprecatedSinceKotlinAndReplaceWith.kt.after +++ b/idea/testData/quickfix/deprecatedSymbolUsage/deprecatedSinceKotlinAndReplaceWith.kt.after @@ -1,5 +1,6 @@ // "Replace with 'newFun()'" "true" +@Suppress("DEPRECATED_SINCE_KOTLIN_OUTSIDE_KOTLIN_SUBPACKAGE") @Deprecated("", ReplaceWith("newFun()")) @DeprecatedSinceKotlin(warningSince = "1.0") fun oldFun() {