diff --git a/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/checkers/expression/FirOptInUsageBaseChecker.kt b/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/checkers/expression/FirOptInUsageBaseChecker.kt index deb049328b1..73ceb2334cf 100644 --- a/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/checkers/expression/FirOptInUsageBaseChecker.kt +++ b/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/checkers/expression/FirOptInUsageBaseChecker.kt @@ -238,7 +238,7 @@ object FirOptInUsageBaseChecker { } val fqName = annotationClassId.asSingleFqName() val reportedMessage = message?.takeIf { it.isNotBlank() } - ?: OptInNames.buildDefaultDiagnosticMessage(OptInNames.buildMessagePrefix(verb), fqName) + ?: OptInNames.buildDefaultDiagnosticMessage(OptInNames.buildMessagePrefix(verb), fqName.asString()) reporter.reportOn(element.source, diagnostic, fqName, reportedMessage, context) } } 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 4a3c90f5108..1b389863c6e 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/resolve/checkers/ExperimentalUsageChecker.kt +++ b/compiler/frontend/src/org/jetbrains/kotlin/resolve/checkers/ExperimentalUsageChecker.kt @@ -119,7 +119,7 @@ class ExperimentalUsageChecker(project: Project) : CallChecker { private val ERROR_LEVEL = Name.identifier("ERROR") internal fun getDefaultDiagnosticMessage(prefix: String): (FqName) -> String = { fqName: FqName -> - OptInNames.buildDefaultDiagnosticMessage(prefix, fqName) + OptInNames.buildDefaultDiagnosticMessage(prefix, fqName.asString()) } private val USAGE_DIAGNOSTICS = ExperimentalityDiagnostics( diff --git a/compiler/testData/cli/jvm/optInEmptyMessage.out b/compiler/testData/cli/jvm/optInEmptyMessage.out index 168a6ceb01f..6154ea01794 100644 --- a/compiler/testData/cli/jvm/optInEmptyMessage.out +++ b/compiler/testData/cli/jvm/optInEmptyMessage.out @@ -1,4 +1,4 @@ -compiler/testData/cli/jvm/optInEmptyMessage.kt:8:5: error: this declaration needs OptIn. Its usage must be marked with '@EmptyMarker' or '@OptIn(EmptyMarker::class)' +compiler/testData/cli/jvm/optInEmptyMessage.kt:8:5: error: this declaration needs opt-in. Its usage must be marked with '@EmptyMarker' or '@OptIn(EmptyMarker::class)' foo() ^ COMPILATION_ERROR diff --git a/compiler/testData/cli/jvm/optInEmptyMessageFir.out b/compiler/testData/cli/jvm/optInEmptyMessageFir.out index 93e72cd154c..56de940031f 100644 --- a/compiler/testData/cli/jvm/optInEmptyMessageFir.out +++ b/compiler/testData/cli/jvm/optInEmptyMessageFir.out @@ -1,7 +1,7 @@ warning: ATTENTION! This build uses in-dev FIR: -Xuse-fir -compiler/testData/cli/jvm/optInEmptyMessageFir.kt:8:5: error: this declaration needs OptIn. Its usage must be marked with '@EmptyMarker' or '@OptIn(EmptyMarker::class)' +compiler/testData/cli/jvm/optInEmptyMessageFir.kt:8:5: error: this declaration needs opt-in. Its usage must be marked with '@EmptyMarker' or '@OptIn(EmptyMarker::class)' foo() ^ COMPILATION_ERROR diff --git a/compiler/testData/cli/jvm/optInOverrideMessage.out b/compiler/testData/cli/jvm/optInOverrideMessage.out index 78c82f2c1ff..4d4631f8618 100644 --- a/compiler/testData/cli/jvm/optInOverrideMessage.out +++ b/compiler/testData/cli/jvm/optInOverrideMessage.out @@ -1,7 +1,7 @@ -compiler/testData/cli/jvm/optInOverrideMessage.kt:16:18: error: base declaration of supertype 'Base' needs OptIn. This API is experimental and can change at any time, please use with care. The declaration override must be annotated with '@Marker' +compiler/testData/cli/jvm/optInOverrideMessage.kt:16:18: error: base declaration of supertype 'Base' needs opt-in. This API is experimental and can change at any time, please use with care. The declaration override must be annotated with '@Marker' or '@OptIn(Marker::class)' override fun foo() {} ^ -compiler/testData/cli/jvm/optInOverrideMessage.kt:18:18: error: base declaration of supertype 'Base' needs OptIn. The declaration override must be annotated with '@EmptyMarker' +compiler/testData/cli/jvm/optInOverrideMessage.kt:18:18: error: base declaration of supertype 'Base' needs opt-in. The declaration override must be annotated with '@EmptyMarker' or '@OptIn(EmptyMarker::class)' override fun bar() {} ^ COMPILATION_ERROR diff --git a/compiler/testData/cli/jvm/optInOverrideMessageFir.out b/compiler/testData/cli/jvm/optInOverrideMessageFir.out index 54278f08d8e..47f7dc82ff1 100644 --- a/compiler/testData/cli/jvm/optInOverrideMessageFir.out +++ b/compiler/testData/cli/jvm/optInOverrideMessageFir.out @@ -1,10 +1,10 @@ warning: ATTENTION! This build uses in-dev FIR: -Xuse-fir -compiler/testData/cli/jvm/optInOverrideMessageFir.kt:16:18: error: base declaration of supertype 'Base' needs OptIn. This API is experimental and can change at any time, please use with care. The declaration override must be annotated with '@Marker' +compiler/testData/cli/jvm/optInOverrideMessageFir.kt:16:18: error: base declaration of supertype 'Base' needs opt-in. This API is experimental and can change at any time, please use with care. The declaration override must be annotated with '@Marker' or '@OptIn(Marker::class)' override fun foo() {} ^ -compiler/testData/cli/jvm/optInOverrideMessageFir.kt:18:18: error: base declaration of supertype 'Base' needs OptIn. The declaration override must be annotated with '@EmptyMarker' +compiler/testData/cli/jvm/optInOverrideMessageFir.kt:18:18: error: base declaration of supertype 'Base' needs opt-in. The declaration override must be annotated with '@EmptyMarker' or '@OptIn(EmptyMarker::class)' override fun bar() {} ^ COMPILATION_ERROR diff --git a/compiler/testData/cli/jvm/useDeclarationThatWasExperimentalWithoutMarker2.out b/compiler/testData/cli/jvm/useDeclarationThatWasExperimentalWithoutMarker2.out index d96ed48710c..e982387af1f 100644 --- a/compiler/testData/cli/jvm/useDeclarationThatWasExperimentalWithoutMarker2.out +++ b/compiler/testData/cli/jvm/useDeclarationThatWasExperimentalWithoutMarker2.out @@ -1,17 +1,17 @@ warning: language version 1.4 is deprecated and its support will be removed in a future version of Kotlin -compiler/testData/cli/jvm/useDeclarationThatWasExperimentalWithoutMarker2.kt:2:13: warning: this declaration needs OptIn. Its usage should be marked with '@kotlin.ExperimentalUnsignedTypes' or '@OptIn(kotlin.ExperimentalUnsignedTypes::class)' +compiler/testData/cli/jvm/useDeclarationThatWasExperimentalWithoutMarker2.kt:2:13: warning: this declaration needs opt-in. Its usage should be marked with '@kotlin.ExperimentalUnsignedTypes' or '@OptIn(kotlin.ExperimentalUnsignedTypes::class)' fun test(p: ULong) { ^ -compiler/testData/cli/jvm/useDeclarationThatWasExperimentalWithoutMarker2.kt:3:12: warning: this declaration needs OptIn. Its usage should be marked with '@kotlin.ExperimentalUnsignedTypes' or '@OptIn(kotlin.ExperimentalUnsignedTypes::class)' +compiler/testData/cli/jvm/useDeclarationThatWasExperimentalWithoutMarker2.kt:3:12: warning: this declaration needs opt-in. Its usage should be marked with '@kotlin.ExperimentalUnsignedTypes' or '@OptIn(kotlin.ExperimentalUnsignedTypes::class)' val z: ULong = p ^ -compiler/testData/cli/jvm/useDeclarationThatWasExperimentalWithoutMarker2.kt:3:20: warning: this declaration needs OptIn. Its usage should be marked with '@kotlin.ExperimentalUnsignedTypes' or '@OptIn(kotlin.ExperimentalUnsignedTypes::class)' +compiler/testData/cli/jvm/useDeclarationThatWasExperimentalWithoutMarker2.kt:3:20: warning: this declaration needs opt-in. Its usage should be marked with '@kotlin.ExperimentalUnsignedTypes' or '@OptIn(kotlin.ExperimentalUnsignedTypes::class)' val z: ULong = p ^ -compiler/testData/cli/jvm/useDeclarationThatWasExperimentalWithoutMarker2.kt:4:5: warning: this declaration needs OptIn. Its usage should be marked with '@kotlin.ExperimentalUnsignedTypes' or '@OptIn(kotlin.ExperimentalUnsignedTypes::class)' +compiler/testData/cli/jvm/useDeclarationThatWasExperimentalWithoutMarker2.kt:4:5: warning: this declaration needs opt-in. Its usage should be marked with '@kotlin.ExperimentalUnsignedTypes' or '@OptIn(kotlin.ExperimentalUnsignedTypes::class)' z.inv() ^ -compiler/testData/cli/jvm/useDeclarationThatWasExperimentalWithoutMarker2.kt:4:7: warning: this declaration needs OptIn. Its usage should be marked with '@kotlin.ExperimentalUnsignedTypes' or '@OptIn(kotlin.ExperimentalUnsignedTypes::class)' +compiler/testData/cli/jvm/useDeclarationThatWasExperimentalWithoutMarker2.kt:4:7: warning: this declaration needs opt-in. Its usage should be marked with '@kotlin.ExperimentalUnsignedTypes' or '@OptIn(kotlin.ExperimentalUnsignedTypes::class)' z.inv() ^ OK diff --git a/core/compiler.common/src/org/jetbrains/kotlin/resolve/checkers/OptInNames.kt b/core/compiler.common/src/org/jetbrains/kotlin/resolve/checkers/OptInNames.kt index cb15382d821..181fc4b8f1d 100644 --- a/core/compiler.common/src/org/jetbrains/kotlin/resolve/checkers/OptInNames.kt +++ b/core/compiler.common/src/org/jetbrains/kotlin/resolve/checkers/OptInNames.kt @@ -39,18 +39,18 @@ object OptInNames { @Suppress("unused") val USE_EXPERIMENTAL_FQ_NAMES = OPT_IN_FQ_NAMES - fun buildDefaultDiagnosticMessage(prefix: String, fqName: FqName): String { - return "$prefix with '@${fqName.asString()}' or '@OptIn(${fqName.asString()}::class)'" + fun buildDefaultDiagnosticMessage(prefix: String, markerName: String): String { + return "$prefix with '@$markerName' or '@OptIn($markerName::class)'" } fun buildMessagePrefix(verb: String): String = - "This declaration needs OptIn. Its usage $verb be marked" + "This declaration needs opt-in. Its usage $verb be marked" fun buildOverrideMessage(supertypeName: String, markerMessage: String?, verb: String, markerName: String): String { - val basePrefix = "Base declaration of supertype '$supertypeName' needs OptIn. " + val basePrefix = "Base declaration of supertype '$supertypeName' needs opt-in. " val markerMessageOrStub = markerMessage ?.takeIf { it.isNotBlank() }?.let { if (it.endsWith(".")) "$it " else "$it. " } ?: "" - val baseSuffix = "The declaration override $verb be annotated with '@$markerName'" + val baseSuffix = buildDefaultDiagnosticMessage("The declaration override $verb be annotated", markerName) return basePrefix + markerMessageOrStub + baseSuffix } } \ No newline at end of file