Replace blank messages in OptIn diagnostics #KT-51358 Fixed

This commit is contained in:
Mikhail Glukhikh
2022-02-21 18:15:04 +03:00
committed by Space
parent 4178c8156a
commit b42c236fb3
9 changed files with 52 additions and 4 deletions
@@ -16,7 +16,6 @@ import org.jetbrains.kotlin.fir.declarations.*
import org.jetbrains.kotlin.fir.declarations.utils.isLocal
import org.jetbrains.kotlin.fir.expressions.FirConstExpression
import org.jetbrains.kotlin.fir.expressions.FirQualifiedAccessExpression
import org.jetbrains.kotlin.fir.references.FirResolvedNamedReference
import org.jetbrains.kotlin.fir.resolve.fullyExpandedType
import org.jetbrains.kotlin.fir.resolve.toFirRegularClassSymbol
import org.jetbrains.kotlin.fir.resolve.toSymbol
@@ -207,7 +206,7 @@ object FirOptInUsageBaseChecker {
Experimentality.Severity.WARNING -> FirErrors.OPT_IN_USAGE to "should"
Experimentality.Severity.ERROR -> FirErrors.OPT_IN_USAGE_ERROR to "must"
}
val reportedMessage = message ?: "This declaration is experimental and its usage $verb be marked"
val reportedMessage = message?.takeIf { it.isNotBlank() } ?: "This declaration is experimental and its usage $verb be marked"
reporter.reportOn(element.source, diagnostic, annotationClassId.asSingleFqName(), reportedMessage, context)
}
}
@@ -71,7 +71,7 @@ class ExperimentalUsageChecker(project: Project) : CallChecker {
val defaultMessage: (FqName) -> String
) : ExperimentalityDiagnostic {
override fun report(trace: BindingTrace, element: PsiElement, fqName: FqName, message: String?) {
trace.reportDiagnosticOnce(factory.on(element, fqName, message ?: defaultMessage(fqName)))
trace.reportDiagnosticOnce(factory.on(element, fqName, message?.takeIf { it.isNotBlank() } ?: defaultMessage(fqName)))
}
}
@@ -480,7 +480,7 @@ class ExperimentalUsageChecker(project: Project) : CallChecker {
Experimentality.Severity.ERROR -> Errors.OPT_IN_OVERRIDE_ERROR to "must"
Experimentality.Severity.FUTURE_ERROR -> Errors.OPT_IN_OVERRIDE_ERROR to "must"
}
val message = experimentality.message
val message = experimentality.message?.takeIf { it.isNotBlank() }
?: "This declaration overrides experimental member of supertype " +
"'${member.containingDeclaration.name.asString()}' and $defaultMessageVerb be annotated " +
"with '@${experimentality.annotationFqName.asString()}'"
+4
View File
@@ -0,0 +1,4 @@
$TESTDATA_DIR$/optInEmptyMessage.kt
-d
$TEMP_DIR$
-opt-in=kotlin.RequiresOptIn
+9
View File
@@ -0,0 +1,9 @@
@RequiresOptIn(message = " ")
annotation class EmptyMarker
@EmptyMarker
fun foo() {}
fun bar() {
foo()
}
+4
View File
@@ -0,0 +1,4 @@
compiler/testData/cli/jvm/optInEmptyMessage.kt:8:5: error: this declaration is experimental and its usage must be marked with '@EmptyMarker' or '@OptIn(EmptyMarker::class)'
foo()
^
COMPILATION_ERROR
+6
View File
@@ -0,0 +1,6 @@
$TESTDATA_DIR$/optInEmptyMessage.kt
-d
$TEMP_DIR$
-opt-in=kotlin.RequiresOptIn
-Xuse-fir
+9
View File
@@ -0,0 +1,9 @@
@RequiresOptIn(message = " ")
annotation class EmptyMarker
@EmptyMarker
fun foo() {}
fun bar() {
foo()
}
+7
View File
@@ -0,0 +1,7 @@
warning: ATTENTION!
This build uses in-dev FIR:
-Xuse-fir
compiler/testData/cli/jvm/optInEmptyMessage.kt:8:5: error: this declaration is experimental and its usage must be marked
foo()
^
COMPILATION_ERROR
@@ -799,6 +799,16 @@ public class CliTestGenerated extends AbstractCliTest {
runTest("compiler/testData/cli/jvm/oldBackendLv16.args");
}
@TestMetadata("optInEmptyMessage.args")
public void testOptInEmptyMessage() throws Exception {
runTest("compiler/testData/cli/jvm/optInEmptyMessage.args");
}
@TestMetadata("optInEmptyMessageFir.args")
public void testOptInEmptyMessageFir() throws Exception {
runTest("compiler/testData/cli/jvm/optInEmptyMessageFir.args");
}
@TestMetadata("pluginSimple.args")
public void testPluginSimple() throws Exception {
runTest("compiler/testData/cli/jvm/pluginSimple.args");