From dd0e919860da30392b96dbf1566b0ef2afd6a71d Mon Sep 17 00:00:00 2001 From: Kirill Rakhman Date: Thu, 21 Dec 2023 14:22:53 +0100 Subject: [PATCH] [FIR] Fix rendering of SUBCLASS_OPT_IN_INAPPLICABLE --- .../FirOptInAnnotationCallChecker.kt | 20 +++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/checkers/expression/FirOptInAnnotationCallChecker.kt b/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/checkers/expression/FirOptInAnnotationCallChecker.kt index 59cf444778a..3f300c53a8f 100644 --- a/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/checkers/expression/FirOptInAnnotationCallChecker.kt +++ b/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/checkers/expression/FirOptInAnnotationCallChecker.kt @@ -54,13 +54,19 @@ object FirOptInAnnotationCallChecker : FirAnnotationCallChecker() { val declaration = context.containingDeclarations.lastOrNull() as? FirClass if (declaration != null) { val kind = declaration.classKind + val classKindRepresentation = kind.representation if (kind == ClassKind.ENUM_CLASS || kind == ClassKind.OBJECT || kind == ClassKind.ANNOTATION_CLASS) { - reporter.reportOn(expression.source, FirErrors.SUBCLASS_OPT_IN_INAPPLICABLE, kind.toString(), context) + reporter.reportOn(expression.source, FirErrors.SUBCLASS_OPT_IN_INAPPLICABLE, classKindRepresentation, context) return } val modality = declaration.modality() if (modality == Modality.FINAL || modality == Modality.SEALED) { - reporter.reportOn(expression.source, FirErrors.SUBCLASS_OPT_IN_INAPPLICABLE, "$modality $kind", context) + reporter.reportOn( + expression.source, + FirErrors.SUBCLASS_OPT_IN_INAPPLICABLE, + "${modality.name.lowercase()} $classKindRepresentation", + context, + ) return } if (declaration.isFun) { @@ -68,7 +74,7 @@ object FirOptInAnnotationCallChecker : FirAnnotationCallChecker() { return } if (declaration.isLocal) { - reporter.reportOn(expression.source, FirErrors.SUBCLASS_OPT_IN_INAPPLICABLE, "local $kind", context) + reporter.reportOn(expression.source, FirErrors.SUBCLASS_OPT_IN_INAPPLICABLE, "local $classKindRepresentation", context) return } } @@ -77,10 +83,16 @@ object FirOptInAnnotationCallChecker : FirAnnotationCallChecker() { } } + private val ClassKind.representation: String + get() = when (this) { + ClassKind.ENUM_ENTRY -> "enum entry" + else -> codeRepresentation!! + } + private fun checkOptInIsEnabled( element: KtSourceElement?, context: CheckerContext, - reporter: DiagnosticReporter + reporter: DiagnosticReporter, ) { val languageVersionSettings = context.session.languageVersionSettings val optInFqNames = languageVersionSettings.getFlag(AnalysisFlags.optIn)