[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
This commit is contained in:
Nikita Bobko
2024-02-05 18:13:17 +01:00
committed by Space Team
parent 11d3ead975
commit 58e1c4c6ac
6 changed files with 6 additions and 5 deletions
@@ -467,7 +467,7 @@ object DIAGNOSTICS_LIST : DiagnosticList("FirErrors") {
parameter<KtModifierKeywordToken>("redundantModifier")
parameter<KtModifierKeywordToken>("conflictingModifier")
}
val DEPRECATED_MODIFIER by warning<PsiElement> {
val DEPRECATED_MODIFIER by error<PsiElement> {
parameter<KtModifierKeywordToken>("deprecatedModifier")
parameter<KtModifierKeywordToken>("actualModifier")
}
@@ -342,7 +342,7 @@ object FirErrors {
val INAPPLICABLE_INFIX_MODIFIER: KtDiagnosticFactory0 by error0<PsiElement>(SourceElementPositioningStrategies.INFIX_MODIFIER)
val REPEATED_MODIFIER: KtDiagnosticFactory1<KtModifierKeywordToken> by error1<PsiElement, KtModifierKeywordToken>()
val REDUNDANT_MODIFIER: KtDiagnosticFactory2<KtModifierKeywordToken, KtModifierKeywordToken> by warning2<PsiElement, KtModifierKeywordToken, KtModifierKeywordToken>()
val DEPRECATED_MODIFIER: KtDiagnosticFactory2<KtModifierKeywordToken, KtModifierKeywordToken> by warning2<PsiElement, KtModifierKeywordToken, KtModifierKeywordToken>()
val DEPRECATED_MODIFIER: KtDiagnosticFactory2<KtModifierKeywordToken, KtModifierKeywordToken> by error2<PsiElement, KtModifierKeywordToken, KtModifierKeywordToken>()
val DEPRECATED_MODIFIER_PAIR: KtDiagnosticFactory2<KtModifierKeywordToken, KtModifierKeywordToken> by warning2<PsiElement, KtModifierKeywordToken, KtModifierKeywordToken>()
val DEPRECATED_MODIFIER_FOR_TARGET: KtDiagnosticFactory2<KtModifierKeywordToken, String> by warning2<PsiElement, KtModifierKeywordToken, String>()
val REDUNDANT_MODIFIER_FOR_TARGET: KtDiagnosticFactory2<KtModifierKeywordToken, String> by warning2<PsiElement, KtModifierKeywordToken, String>()
@@ -200,6 +200,7 @@ val FIR_NON_SUPPRESSIBLE_ERROR_NAMES: Set<String> = setOf(
"EXPOSED_TYPE_PARAMETER_BOUND",
"INAPPLICABLE_INFIX_MODIFIER",
"REPEATED_MODIFIER",
"DEPRECATED_MODIFIER",
"INCOMPATIBLE_MODIFIERS",
"WRONG_MODIFIER_TARGET",
"OPERATOR_MODIFIER_REQUIRED",
@@ -133,7 +133,7 @@ object FirModifierChecker : FirBasicDeclarationChecker(MppCheckerKind.Common) {
}
}
val deprecatedModifierReplacement = deprecatedModifierMap[modifierToken]
val deprecatedModifierReplacement = deprecatedKmpModifierMap[modifierToken]
if (deprecatedModifierReplacement != null) {
reporter.reportOn(
modifierSource,
@@ -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 {
@@ -288,7 +288,7 @@ val deprecatedTargetMap = mapOf<KtKeywordToken, Set<KotlinTarget>>()
val deprecatedParentTargetMap = mapOf<KtKeywordToken, Set<KotlinTarget>>()
val deprecatedModifierMap = mapOf(
val deprecatedKmpModifierMap = mapOf(
HEADER_KEYWORD to EXPECT_KEYWORD,
IMPL_KEYWORD to ACTUAL_KEYWORD
)