From 58e1c4c6ac211c865e912968252e9004538b1494 Mon Sep 17 00:00:00 2001 From: Nikita Bobko Date: Mon, 5 Feb 2024 18:13:17 +0100 Subject: [PATCH] [FIR] Kmp: Deprecate header/impl keywords Review: https://jetbrains.team/p/kt/reviews/14224/timeline Timeline: **(1)** Kotlin 1.1.60 https://github.com/JetBrains/kotlin/commit/59efedf610a25b004edf3d19897ce4dfca28ddb2 `header` keyword is introduced (committed on Dec 13, 2016) **(2)** Kotlin `header`/`impl` has been deprecated (warning) at least since 1.1.60 https://github.com/JetBrains/kotlin/commit/5d251062677e09d607f295189b7978d5833e448f (committed on Sep 15, 2017) **(3)** 1.1.60 release https://repo1.maven.org/maven2/org/jetbrains/kotlin/kotlin-compiler/1.1.60/ Nov 13, 2017 It sounds stupid but it looks like `header` was introduced and deprecated right in the same release. Though it may be possible that we had a release between **(1)** and **(2)** that I couldn't find Anyway the keywords have been deprecated since basically forever The fix is not perfect "The perfect fix" would be: 1. Introduce a separate `DEPRECATED_MODIFIER_ERROR` diagnostic 2. Introduce LanguageVersionSettings for the `DEPRECATED_MODIFIER_ERROR` diagnostic But "the perfect fix" requires: 1. Adopting `ReplaceModifierFix` in the IDE to make it work with the new diagnostic. `ReplaceModifierFix` is only implemented in K1 IDE. So there are two ways: 1. Create a KTIJ ticket to port the diagnostic to K2 IDE (it needs to be ported anyway), and **mention** in the ticket that `DEPRECATED_MODIFIER_ERROR` also needs to be supported in K2 IDE. It's the ticket that nobody will probably find and fix 2. Go and port `ReplaceModifierFix` to K2 IDE myself. It's fairly simple task, but I've not worked in intellij for quite a while, and it will take me too much time to index and compile Considering that DEPRECATED_MODIFIER diagnostic is used only to report `header`/`impl`, and there are literally 0 known cases when people use it. It's just easier to convert the diagnostic to error in K2 Related tests: - compiler/testData/diagnostics/tests/multiplatform/deprecated/header.kt ^KT-59839 Fixed --- .../fir/checkers/generator/diagnostics/FirDiagnosticsList.kt | 2 +- .../org/jetbrains/kotlin/fir/analysis/diagnostics/FirErrors.kt | 2 +- .../fir/analysis/diagnostics/FirNonSuppressibleErrorNames.kt | 1 + .../fir/analysis/checkers/declaration/FirModifierChecker.kt | 2 +- .../src/org/jetbrains/kotlin/resolve/ModifiersChecker.kt | 2 +- .../src/org/jetbrains/kotlin/resolve/ModifierCheckerHelpers.kt | 2 +- 6 files changed, 6 insertions(+), 5 deletions(-) diff --git a/compiler/fir/checkers/checkers-component-generator/src/org/jetbrains/kotlin/fir/checkers/generator/diagnostics/FirDiagnosticsList.kt b/compiler/fir/checkers/checkers-component-generator/src/org/jetbrains/kotlin/fir/checkers/generator/diagnostics/FirDiagnosticsList.kt index fc567b4169f..e15e023e68e 100644 --- a/compiler/fir/checkers/checkers-component-generator/src/org/jetbrains/kotlin/fir/checkers/generator/diagnostics/FirDiagnosticsList.kt +++ b/compiler/fir/checkers/checkers-component-generator/src/org/jetbrains/kotlin/fir/checkers/generator/diagnostics/FirDiagnosticsList.kt @@ -467,7 +467,7 @@ object DIAGNOSTICS_LIST : DiagnosticList("FirErrors") { parameter("redundantModifier") parameter("conflictingModifier") } - val DEPRECATED_MODIFIER by warning { + val DEPRECATED_MODIFIER by error { parameter("deprecatedModifier") parameter("actualModifier") } diff --git a/compiler/fir/checkers/gen/org/jetbrains/kotlin/fir/analysis/diagnostics/FirErrors.kt b/compiler/fir/checkers/gen/org/jetbrains/kotlin/fir/analysis/diagnostics/FirErrors.kt index 03efd783a91..4b70ab5bb5b 100644 --- a/compiler/fir/checkers/gen/org/jetbrains/kotlin/fir/analysis/diagnostics/FirErrors.kt +++ b/compiler/fir/checkers/gen/org/jetbrains/kotlin/fir/analysis/diagnostics/FirErrors.kt @@ -342,7 +342,7 @@ object FirErrors { val INAPPLICABLE_INFIX_MODIFIER: KtDiagnosticFactory0 by error0(SourceElementPositioningStrategies.INFIX_MODIFIER) val REPEATED_MODIFIER: KtDiagnosticFactory1 by error1() val REDUNDANT_MODIFIER: KtDiagnosticFactory2 by warning2() - val DEPRECATED_MODIFIER: KtDiagnosticFactory2 by warning2() + val DEPRECATED_MODIFIER: KtDiagnosticFactory2 by error2() val DEPRECATED_MODIFIER_PAIR: KtDiagnosticFactory2 by warning2() val DEPRECATED_MODIFIER_FOR_TARGET: KtDiagnosticFactory2 by warning2() val REDUNDANT_MODIFIER_FOR_TARGET: KtDiagnosticFactory2 by warning2() diff --git a/compiler/fir/checkers/gen/org/jetbrains/kotlin/fir/analysis/diagnostics/FirNonSuppressibleErrorNames.kt b/compiler/fir/checkers/gen/org/jetbrains/kotlin/fir/analysis/diagnostics/FirNonSuppressibleErrorNames.kt index a2d3305eb77..66af294e8a2 100644 --- a/compiler/fir/checkers/gen/org/jetbrains/kotlin/fir/analysis/diagnostics/FirNonSuppressibleErrorNames.kt +++ b/compiler/fir/checkers/gen/org/jetbrains/kotlin/fir/analysis/diagnostics/FirNonSuppressibleErrorNames.kt @@ -200,6 +200,7 @@ val FIR_NON_SUPPRESSIBLE_ERROR_NAMES: Set = setOf( "EXPOSED_TYPE_PARAMETER_BOUND", "INAPPLICABLE_INFIX_MODIFIER", "REPEATED_MODIFIER", + "DEPRECATED_MODIFIER", "INCOMPATIBLE_MODIFIERS", "WRONG_MODIFIER_TARGET", "OPERATOR_MODIFIER_REQUIRED", diff --git a/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/checkers/declaration/FirModifierChecker.kt b/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/checkers/declaration/FirModifierChecker.kt index 2d875f4ed21..0c1a22acb9b 100644 --- a/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/checkers/declaration/FirModifierChecker.kt +++ b/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/checkers/declaration/FirModifierChecker.kt @@ -133,7 +133,7 @@ object FirModifierChecker : FirBasicDeclarationChecker(MppCheckerKind.Common) { } } - val deprecatedModifierReplacement = deprecatedModifierMap[modifierToken] + val deprecatedModifierReplacement = deprecatedKmpModifierMap[modifierToken] if (deprecatedModifierReplacement != null) { reporter.reportOn( modifierSource, diff --git a/compiler/frontend/src/org/jetbrains/kotlin/resolve/ModifiersChecker.kt b/compiler/frontend/src/org/jetbrains/kotlin/resolve/ModifiersChecker.kt index 66b1d6644db..ba0b0899dd9 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/resolve/ModifiersChecker.kt +++ b/compiler/frontend/src/org/jetbrains/kotlin/resolve/ModifiersChecker.kt @@ -122,7 +122,7 @@ object ModifierCheckerCore { trace.report(Errors.WRONG_MODIFIER_TARGET.on(node.psi, modifier, actualTargets.firstOrNull()?.description ?: "this")) return false } - val deprecatedModifierReplacement = deprecatedModifierMap[modifier] + val deprecatedModifierReplacement = deprecatedKmpModifierMap[modifier] val deprecatedTargets = deprecatedTargetMap[modifier] ?: emptySet() val redundantTargets = redundantTargetMap[modifier] ?: emptySet() when { diff --git a/compiler/psi/src/org/jetbrains/kotlin/resolve/ModifierCheckerHelpers.kt b/compiler/psi/src/org/jetbrains/kotlin/resolve/ModifierCheckerHelpers.kt index 023f5fb6e6d..6fe13baa46e 100644 --- a/compiler/psi/src/org/jetbrains/kotlin/resolve/ModifierCheckerHelpers.kt +++ b/compiler/psi/src/org/jetbrains/kotlin/resolve/ModifierCheckerHelpers.kt @@ -288,7 +288,7 @@ val deprecatedTargetMap = mapOf>() val deprecatedParentTargetMap = mapOf>() -val deprecatedModifierMap = mapOf( +val deprecatedKmpModifierMap = mapOf( HEADER_KEYWORD to EXPECT_KEYWORD, IMPL_KEYWORD to ACTUAL_KEYWORD )