-
Notifications
You must be signed in to change notification settings - Fork 6.1k
Support -Xwarning-level for Opt-in CLI diagnostics
#5568
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
KvanTTT
wants to merge
5
commits into
master
from
rr/ikochurkin/support-warning-level-for-opt-in-cli-diagnostics
Closed
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
aa71b4d
[Test] Reproduce non-suppressible OptIn CLI warnings (KT-48419)
KvanTTT 62729f4
Transform `AnalyzerWithCompilerReport.convertSeverity` to `Severity.t…
KvanTTT a9287b1
Move `CliDiagnostics` from `org.jetbrains.kotlin.fir.cli` to `org.jet…
KvanTTT 524b4c7
Introduce `BaseDiagnosticsCollector.reportIfNeeded`
KvanTTT 1429a28
[FIR] Introduce identifiers for opt-in CLI diagnostics that can be co…
KvanTTT File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -26,10 +26,8 @@ import org.jetbrains.kotlin.cli.common.arguments.CommonCompilerArguments | |
| import org.jetbrains.kotlin.cli.common.messages.* | ||
| import org.jetbrains.kotlin.config.CompilerConfiguration | ||
| import org.jetbrains.kotlin.config.IncrementalCompilation | ||
| import org.jetbrains.kotlin.config.LanguageVersionSettings | ||
| import org.jetbrains.kotlin.config.languageVersionSettings | ||
| import org.jetbrains.kotlin.config.messageCollector | ||
| import org.jetbrains.kotlin.diagnostics.DiagnosticBaseContext | ||
| import org.jetbrains.kotlin.diagnostics.KtSourcelessDiagnosticFactory | ||
| import org.jetbrains.kotlin.fir.declarations.FirFile | ||
| import org.jetbrains.kotlin.fir.packageFqName | ||
|
|
@@ -157,10 +155,6 @@ fun disposeRootInWriteAction(disposable: Disposable) { | |
| } | ||
|
|
||
| fun CompilerConfiguration.reportIfNeeded(factory: KtSourcelessDiagnosticFactory, message: String) { | ||
| val diagnostic = factory.create(message, object : DiagnosticBaseContext { | ||
| override val languageVersionSettings: LanguageVersionSettings | ||
| get() = [email protected] | ||
|
|
||
| }) ?: return | ||
| messageCollector.report(AnalyzerWithCompilerReport.convertSeverity(diagnostic.severity), message) | ||
| val effectiveSeverity = factory.getEffectiveSeverity([email protected]) ?: return | ||
| messageCollector.report(effectiveSeverity.toCompilerMessageSeverity(), message) | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
40 changes: 40 additions & 0 deletions
40
compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/diagnostics/CliDiagnostics.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,40 @@ | ||
| /* | ||
| * Copyright 2010-2025 JetBrains s.r.o. and Kotlin Programming Language contributors. | ||
| * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. | ||
| */ | ||
|
|
||
| package org.jetbrains.kotlin.fir.analysis.diagnostics | ||
|
|
||
| import org.jetbrains.kotlin.diagnostics.KtDiagnosticFactoryToRendererMap | ||
| import org.jetbrains.kotlin.diagnostics.KtDiagnosticsContainer | ||
| import org.jetbrains.kotlin.diagnostics.KtSourcelessDiagnosticFactory | ||
| import org.jetbrains.kotlin.diagnostics.errorWithoutSource | ||
| import org.jetbrains.kotlin.diagnostics.rendering.BaseDiagnosticRendererFactory | ||
| import org.jetbrains.kotlin.diagnostics.rendering.BaseSourcelessDiagnosticFactory | ||
| import org.jetbrains.kotlin.diagnostics.warningWithoutSource | ||
| import org.jetbrains.kotlin.fir.analysis.diagnostics.CliDiagnostics.CLI_COMPILER_PLUGIN_IS_EXPERIMENTAL | ||
| import org.jetbrains.kotlin.fir.analysis.diagnostics.CliDiagnostics.CLI_NOT_AN_OPT_IN_REQUIREMENT_MARKER | ||
| import org.jetbrains.kotlin.fir.analysis.diagnostics.CliDiagnostics.CLI_OPT_IN_REQUIREMENT_MARKER_IS_DEPRECATED | ||
| import org.jetbrains.kotlin.fir.analysis.diagnostics.CliDiagnostics.CLI_OPT_IN_REQUIREMENT_MARKER_IS_DEPRECATED_ERROR | ||
| import org.jetbrains.kotlin.fir.analysis.diagnostics.CliDiagnostics.CLI_OPT_IN_REQUIREMENT_MARKER_IS_UNRESOLVED | ||
| import kotlin.getValue | ||
|
|
||
| object CliDiagnostics : KtDiagnosticsContainer() { | ||
| val CLI_COMPILER_PLUGIN_IS_EXPERIMENTAL: KtSourcelessDiagnosticFactory by warningWithoutSource() | ||
| val CLI_OPT_IN_REQUIREMENT_MARKER_IS_UNRESOLVED: KtSourcelessDiagnosticFactory by warningWithoutSource() | ||
| val CLI_NOT_AN_OPT_IN_REQUIREMENT_MARKER: KtSourcelessDiagnosticFactory by warningWithoutSource() | ||
| val CLI_OPT_IN_REQUIREMENT_MARKER_IS_DEPRECATED: KtSourcelessDiagnosticFactory by warningWithoutSource() | ||
| val CLI_OPT_IN_REQUIREMENT_MARKER_IS_DEPRECATED_ERROR: KtSourcelessDiagnosticFactory by errorWithoutSource() | ||
|
|
||
| override fun getRendererFactory(): BaseDiagnosticRendererFactory = KtDiagnosticMessagesCli | ||
| } | ||
|
|
||
| object KtDiagnosticMessagesCli : BaseSourcelessDiagnosticFactory() { | ||
| override val MAP: KtDiagnosticFactoryToRendererMap by KtDiagnosticFactoryToRendererMap("CLI") { map -> | ||
| map.put(CLI_COMPILER_PLUGIN_IS_EXPERIMENTAL, MESSAGE_PLACEHOLDER) | ||
| map.put(CLI_OPT_IN_REQUIREMENT_MARKER_IS_UNRESOLVED, MESSAGE_PLACEHOLDER) | ||
| map.put(CLI_NOT_AN_OPT_IN_REQUIREMENT_MARKER, MESSAGE_PLACEHOLDER) | ||
| map.put(CLI_OPT_IN_REQUIREMENT_MARKER_IS_DEPRECATED, MESSAGE_PLACEHOLDER) | ||
| map.put(CLI_OPT_IN_REQUIREMENT_MARKER_IS_DEPRECATED_ERROR, MESSAGE_PLACEHOLDER) | ||
| } | ||
| } | ||
27 changes: 0 additions & 27 deletions
27
compiler/fir/entrypoint/src/org/jetbrains/kotlin/fir/cli/CliDiagnostics.kt
This file was deleted.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| interface NotAnAnnotation | ||
|
|
||
| @Deprecated("Warning", level = DeprecationLevel.WARNING) | ||
| @RequiresOptIn | ||
| @Retention(AnnotationRetention.BINARY) | ||
| annotation class Warning | ||
|
|
||
| @Deprecated("Error", level = DeprecationLevel.ERROR) | ||
| @RequiresOptIn | ||
| annotation class Error |
8 changes: 8 additions & 0 deletions
8
compiler/testData/cli/metadata/optInErrorIsNotSuppressible.args
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| $TESTDATA_DIR$/optInDiagnostics.kt | ||
| -d | ||
| $TEMP_DIR$ | ||
| -cp | ||
| $TESTDATA_DIR$/../../../../dist/common/kotlin-stdlib-common.klib | ||
| -Xtarget-platform=JVM,JS,WasmJs,WasmWasi,Native | ||
| -opt-in=Error | ||
| -Xwarning-level=CLI_OPT_IN_REQUIREMENT_MARKER_IS_DEPRECATED_ERROR\:disabled |
2 changes: 2 additions & 0 deletions
2
compiler/testData/cli/metadata/optInErrorIsNotSuppressible.out
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,2 @@ | ||
| error: diagnostic "CLI_OPT_IN_REQUIREMENT_MARKER_IS_DEPRECATED_ERROR" is an error. Changing the severity of errors is prohibited | ||
| COMPILATION_ERROR |
14 changes: 14 additions & 0 deletions
14
compiler/testData/cli/metadata/optInWarningsAreDisabled.args
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,14 @@ | ||
| $TESTDATA_DIR$/optInDiagnostics.kt | ||
| -d | ||
| $TEMP_DIR$ | ||
| -cp | ||
| $TESTDATA_DIR$/../../../../dist/common/kotlin-stdlib-common.klib | ||
| -Xtarget-platform=JVM,JS,WasmJs,WasmWasi,Native | ||
| -opt-in=Unresolved | ||
| -opt-in=NotAnAnnotation | ||
| -opt-in=kotlin.RequiresOptIn | ||
| -opt-in=Warning | ||
| -Werror | ||
| -Xwarning-level=CLI_OPT_IN_REQUIREMENT_MARKER_IS_UNRESOLVED\:disabled | ||
| -Xwarning-level=CLI_NOT_AN_OPT_IN_REQUIREMENT_MARKER\:disabled | ||
| -Xwarning-level=CLI_OPT_IN_REQUIREMENT_MARKER_IS_DEPRECATED\:disabled |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| OK |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| $TESTDATA_DIR$/optInDiagnostics.kt | ||
| -d | ||
| $TEMP_DIR$ | ||
| -cp | ||
| $TESTDATA_DIR$/../../../../dist/common/kotlin-stdlib-common.klib | ||
| -Xtarget-platform=JVM,JS,WasmJs,WasmWasi,Native | ||
| -opt-in=Unresolved | ||
| -opt-in=NotAnAnnotation | ||
| -opt-in=kotlin.RequiresOptIn | ||
| -opt-in=Warning | ||
| -Xwarning-level=CLI_OPT_IN_REQUIREMENT_MARKER_IS_UNRESOLVED\:error | ||
| -Xwarning-level=CLI_NOT_AN_OPT_IN_REQUIREMENT_MARKER\:error | ||
| -Xwarning-level=CLI_OPT_IN_REQUIREMENT_MARKER_IS_DEPRECATED\:error |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| error: opt-in requirement marker Unresolved is unresolved. Please make sure it's present in the module dependencies | ||
| error: class NotAnAnnotation is not an opt-in requirement marker | ||
| error: opt-in requirement marker Warning is deprecated. Warning | ||
| COMPILATION_ERROR |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure if
CLI_prefixes are needed here. It probably makes sense to remove them.