diff --git a/analysis/analysis-api/testData/symbols/symbolByPsi/deprecated.txt b/analysis/analysis-api/testData/symbols/symbolByPsi/deprecated.txt index 2b2817ec297..1f202955654 100644 --- a/analysis/analysis-api/testData/symbols/symbolByPsi/deprecated.txt +++ b/analysis/analysis-api/testData/symbols/symbolByPsi/deprecated.txt @@ -806,11 +806,11 @@ KtKotlinPropertySymbol: getContainingFileSymbol: KtFileSymbol(deprecated.kt) getContainingJvmClassName: DeprecatedKt getContainingModule: KtSourceModule "Sources of main" - deprecationStatus: DeprecationInfo(deprecationLevel=ERROR, propagatesToOverrides=true, message=null) - getterDeprecationStatus: DeprecationInfo(deprecationLevel=ERROR, propagatesToOverrides=true, message=null) + deprecationStatus: DeprecationInfo(deprecationLevel=ERROR, propagatesToOverrides=true, message=don't use j) + getterDeprecationStatus: DeprecationInfo(deprecationLevel=ERROR, propagatesToOverrides=true, message=don't use j) javaGetterName: getJ javaSetterName: null - setterDeprecationStatus: DeprecationInfo(deprecationLevel=ERROR, propagatesToOverrides=true, message=null) + setterDeprecationStatus: DeprecationInfo(deprecationLevel=ERROR, propagatesToOverrides=true, message=don't use j) KtKotlinPropertySymbol: annotationsList: [ @@ -892,11 +892,11 @@ KtKotlinPropertySymbol: getContainingFileSymbol: KtFileSymbol(deprecated.kt) getContainingJvmClassName: DeprecatedKt getContainingModule: KtSourceModule "Sources of main" - deprecationStatus: DeprecationInfo(deprecationLevel=HIDDEN, propagatesToOverrides=true, message=null) - getterDeprecationStatus: DeprecationInfo(deprecationLevel=HIDDEN, propagatesToOverrides=true, message=null) + deprecationStatus: DeprecationInfo(deprecationLevel=HIDDEN, propagatesToOverrides=true, message=don't use j2) + getterDeprecationStatus: DeprecationInfo(deprecationLevel=HIDDEN, propagatesToOverrides=true, message=don't use j2) javaGetterName: getJ2 javaSetterName: null - setterDeprecationStatus: DeprecationInfo(deprecationLevel=HIDDEN, propagatesToOverrides=true, message=null) + setterDeprecationStatus: DeprecationInfo(deprecationLevel=HIDDEN, propagatesToOverrides=true, message=don't use j2) KtKotlinPropertySymbol: annotationsList: [] diff --git a/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/diagnostics/FirErrorsDefaultMessages.kt b/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/diagnostics/FirErrorsDefaultMessages.kt index 6fe7546be70..6fe52f5d6ef 100644 --- a/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/diagnostics/FirErrorsDefaultMessages.kt +++ b/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/diagnostics/FirErrorsDefaultMessages.kt @@ -764,8 +764,8 @@ object FirErrorsDefaultMessages : BaseDiagnosticRendererFactory() { map.put(VAL_OR_VAR_ON_FUN_PARAMETER, "''{0}'' on function parameter is prohibited.", TO_STRING) map.put(VAL_OR_VAR_ON_CATCH_PARAMETER, "''{0}'' on catch parameter is prohibited.", TO_STRING) map.put(VAL_OR_VAR_ON_SECONDARY_CONSTRUCTOR_PARAMETER, "''{0}'' on secondary constructor parameter is prohibited.", TO_STRING) - map.put(DEPRECATION, "''{0}'' is deprecated. {1}.", SYMBOL, STRING) - map.put(DEPRECATION_ERROR, "''{0}'' is deprecated. {1}.", SYMBOL, STRING) + map.put(DEPRECATION, "''{0}'' is deprecated.{1}", SYMBOL, OPTIONAL_SENTENCE) + map.put(DEPRECATION_ERROR, "''{0}'' is deprecated.{1}", SYMBOL, OPTIONAL_SENTENCE) map.put(VERSION_REQUIREMENT_DEPRECATION, "''{0}''{1} should not be used in Kotlin {2}.{3}", SYMBOL, REQUIRE_KOTLIN_VERSION, STRING, OPTIONAL_SENTENCE) map.put(VERSION_REQUIREMENT_DEPRECATION_ERROR, "''{0}''{1} cannot be used in Kotlin {2}.{3}", SYMBOL, REQUIRE_KOTLIN_VERSION, STRING, OPTIONAL_SENTENCE) map.put(TYPEALIAS_EXPANSION_DEPRECATION, "''{0}'' uses ''{1}'', which is deprecated. {2}.", SYMBOL, SYMBOL, STRING) diff --git a/compiler/fir/providers/src/org/jetbrains/kotlin/fir/declarations/deprecationUtils.kt b/compiler/fir/providers/src/org/jetbrains/kotlin/fir/declarations/deprecationUtils.kt index 55db01c48e0..9d8f9f8d1ee 100644 --- a/compiler/fir/providers/src/org/jetbrains/kotlin/fir/declarations/deprecationUtils.kt +++ b/compiler/fir/providers/src/org/jetbrains/kotlin/fir/declarations/deprecationUtils.kt @@ -287,6 +287,7 @@ private fun List.extractDeprecationAnnotationInfoPerUseSite( it.unexpandedClassId == StandardClassIds.Annotations.DeprecatedSinceKotlin } val message = deprecated.getStringArgument(ParameterNames.deprecatedMessage) + ?: deprecated.getFirstArgumentStringIfNotNamed() val deprecatedInfo = if (deprecatedSinceKotlin == null) { @@ -310,6 +311,12 @@ private fun List.extractDeprecationAnnotationInfoPerUseSite( } } +private fun FirAnnotation.getFirstArgumentStringIfNotNamed(): String? { + if (this !is FirAnnotationCall) return null + val firstArgument = argumentList.arguments.firstOrNull() ?: return null + return (firstArgument as? FirConstExpression<*>)?.value?.toString() +} + fun FirBasedSymbol<*>.isDeprecationLevelHidden(languageVersionSettings: LanguageVersionSettings): Boolean = when (this) { diff --git a/compiler/testData/cli/jvm/experimentalDeprecated.out b/compiler/testData/cli/jvm/experimentalDeprecated.out index 00da2d0dd88..5556c4bab32 100644 --- a/compiler/testData/cli/jvm/experimentalDeprecated.out +++ b/compiler/testData/cli/jvm/experimentalDeprecated.out @@ -1,3 +1,3 @@ -error: opt-in requirement marker org.test.Error is deprecated -error: opt-in requirement marker org.test.Hidden is deprecated +error: opt-in requirement marker org.test.Error is deprecated. Error +error: opt-in requirement marker org.test.Hidden is deprecated. Hidden COMPILATION_ERROR diff --git a/compiler/testData/cli/jvm/experimentalDeprecatedWarning.out b/compiler/testData/cli/jvm/experimentalDeprecatedWarning.out index 886f17b862a..03e36c75643 100644 --- a/compiler/testData/cli/jvm/experimentalDeprecatedWarning.out +++ b/compiler/testData/cli/jvm/experimentalDeprecatedWarning.out @@ -1,3 +1,3 @@ warning: argument -Xopt-in is deprecated. Please use -opt-in instead -warning: opt-in requirement marker org.test.Warning is deprecated +warning: opt-in requirement marker org.test.Warning is deprecated. Warning OK diff --git a/compiler/testData/diagnostics/tests/deprecated/deprecatedError.diag.txt b/compiler/testData/diagnostics/tests/deprecated/deprecatedError.diag.txt new file mode 100644 index 00000000000..73c840d07f3 --- /dev/null +++ b/compiler/testData/diagnostics/tests/deprecated/deprecatedError.diag.txt @@ -0,0 +1,9 @@ +/deprecatedError.kt:10:13: error: using 'C' is an error. alas +fun test(c: C) { + ^ +/deprecatedError.kt:11:5: error: using 'foo(String): Unit' is an error. alas + foo("") + ^ +/deprecatedError.kt:12:5: error: using 'C' is an error. alas + C() + ^ diff --git a/compiler/testData/diagnostics/tests/deprecated/deprecatedError.fir.diag.txt b/compiler/testData/diagnostics/tests/deprecated/deprecatedError.fir.diag.txt new file mode 100644 index 00000000000..9ceb970d536 --- /dev/null +++ b/compiler/testData/diagnostics/tests/deprecated/deprecatedError.fir.diag.txt @@ -0,0 +1,5 @@ +/deprecatedError.kt:(237,238): error: '@Deprecated(...) class C : Any' is deprecated. alas. + +/deprecatedError.kt:(246,249): error: '@Deprecated(...) fun foo(s: @R|Foo|() String): Unit' is deprecated. alas. + +/deprecatedError.kt:(258,259): error: 'constructor(): C' is deprecated. alas. diff --git a/compiler/testData/diagnostics/tests/deprecated/deprecatedError.kt b/compiler/testData/diagnostics/tests/deprecated/deprecatedError.kt index a1dc23f49b9..4569ef0b8e4 100644 --- a/compiler/testData/diagnostics/tests/deprecated/deprecatedError.kt +++ b/compiler/testData/diagnostics/tests/deprecated/deprecatedError.kt @@ -1,12 +1,16 @@ // FIR_IDENTICAL +// RENDER_DIAGNOSTICS_FULL_TEXT // !DIAGNOSTICS: -UNUSED_PARAMETER @Deprecated("alas", level = DeprecationLevel.ERROR) -fun foo() {} +fun foo(s: @Foo String) {} @Deprecated("alas", level = DeprecationLevel.ERROR) class C fun test(c: C) { - foo() + foo("") C() -} \ No newline at end of file +} + +@Target(AnnotationTarget.TYPE) +annotation class Foo \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/deprecated/deprecatedError.txt b/compiler/testData/diagnostics/tests/deprecated/deprecatedError.txt deleted file mode 100644 index 4d36f3f2bfe..00000000000 --- a/compiler/testData/diagnostics/tests/deprecated/deprecatedError.txt +++ /dev/null @@ -1,11 +0,0 @@ -package - -@kotlin.Deprecated(level = DeprecationLevel.ERROR, message = "alas") public fun foo(): kotlin.Unit -public fun test(/*0*/ c: C): kotlin.Unit - -@kotlin.Deprecated(level = DeprecationLevel.ERROR, message = "alas") public final class C { - public constructor C() - 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 -}