diff --git a/analysis/analysis-api-fir/src/org/jetbrains/kotlin/analysis/api/fir/diagnostics/KtFirDataClassConverters.kt b/analysis/analysis-api-fir/src/org/jetbrains/kotlin/analysis/api/fir/diagnostics/KtFirDataClassConverters.kt index 82ec477f3b435..d9965bf706bd6 100644 --- a/analysis/analysis-api-fir/src/org/jetbrains/kotlin/analysis/api/fir/diagnostics/KtFirDataClassConverters.kt +++ b/analysis/analysis-api-fir/src/org/jetbrains/kotlin/analysis/api/fir/diagnostics/KtFirDataClassConverters.kt @@ -1372,6 +1372,12 @@ internal val KT_DIAGNOSTIC_CONVERTER = KtDiagnosticConverterBuilder.buildConvert token, ) } + add(FirErrors.SEALED_INLINE_CLASS_WITH_UNDERLYING_VALUE) { firDiagnostic -> + SealedInlineClassWithUnderlyingValueImpl( + firDiagnostic as KtPsiDiagnostic, + token, + ) + } add(FirErrors.SEALED_INLINE_CHILD_NOT_VALUE) { firDiagnostic -> SealedInlineChildNotValueImpl( firDiagnostic as KtPsiDiagnostic, diff --git a/analysis/analysis-api-fir/src/org/jetbrains/kotlin/analysis/api/fir/diagnostics/KtFirDiagnostics.kt b/analysis/analysis-api-fir/src/org/jetbrains/kotlin/analysis/api/fir/diagnostics/KtFirDiagnostics.kt index c83379aa12da2..32f3789670b6d 100644 --- a/analysis/analysis-api-fir/src/org/jetbrains/kotlin/analysis/api/fir/diagnostics/KtFirDiagnostics.kt +++ b/analysis/analysis-api-fir/src/org/jetbrains/kotlin/analysis/api/fir/diagnostics/KtFirDiagnostics.kt @@ -990,6 +990,10 @@ sealed class KtFirDiagnostic : KtDiagnosticWithPsi { override val diagnosticClass get() = ValueObjectNotSealedInlineChild::class } + abstract class SealedInlineClassWithUnderlyingValue : KtFirDiagnostic() { + override val diagnosticClass get() = SealedInlineClassWithUnderlyingValue::class + } + abstract class SealedInlineChildNotValue : KtFirDiagnostic() { override val diagnosticClass get() = SealedInlineChildNotValue::class } diff --git a/analysis/analysis-api-fir/src/org/jetbrains/kotlin/analysis/api/fir/diagnostics/KtFirDiagnosticsImpl.kt b/analysis/analysis-api-fir/src/org/jetbrains/kotlin/analysis/api/fir/diagnostics/KtFirDiagnosticsImpl.kt index 0195c3b393661..67758688dd2e8 100644 --- a/analysis/analysis-api-fir/src/org/jetbrains/kotlin/analysis/api/fir/diagnostics/KtFirDiagnosticsImpl.kt +++ b/analysis/analysis-api-fir/src/org/jetbrains/kotlin/analysis/api/fir/diagnostics/KtFirDiagnosticsImpl.kt @@ -1187,6 +1187,11 @@ internal class ValueObjectNotSealedInlineChildImpl( override val token: KtLifetimeToken, ) : KtFirDiagnostic.ValueObjectNotSealedInlineChild(), KtAbstractFirDiagnostic +internal class SealedInlineClassWithUnderlyingValueImpl( + override val firDiagnostic: KtPsiDiagnostic, + override val token: KtLifetimeToken, +) : KtFirDiagnostic.SealedInlineClassWithUnderlyingValue(), KtAbstractFirDiagnostic + internal class SealedInlineChildNotValueImpl( override val firDiagnostic: KtPsiDiagnostic, override val token: KtLifetimeToken, 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 689a5dc928eed..9ffd2f3c82167 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 @@ -426,6 +426,7 @@ object DIAGNOSTICS_LIST : DiagnosticList("FirErrors") { val INNER_CLASS_INSIDE_VALUE_CLASS by error(PositioningStrategy.INNER_MODIFIER) val VALUE_CLASS_CANNOT_BE_CLONEABLE by error(PositioningStrategy.INLINE_OR_VALUE_MODIFIER) val VALUE_OBJECT_NOT_SEALED_INLINE_CHILD by error(PositioningStrategy.INLINE_OR_VALUE_MODIFIER) + val SEALED_INLINE_CLASS_WITH_UNDERLYING_VALUE by error(PositioningStrategy.INLINE_OR_VALUE_MODIFIER) val SEALED_INLINE_CHILD_NOT_VALUE by error() val SEALED_INLINE_CHILD_OVERLAPPING_TYPE by error(PositioningStrategy.INLINE_OR_VALUE_MODIFIER) } 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 78442c25e6ddb..96fc6f25b3453 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 @@ -322,6 +322,7 @@ object FirErrors { val INNER_CLASS_INSIDE_VALUE_CLASS by error0(SourceElementPositioningStrategies.INNER_MODIFIER) val VALUE_CLASS_CANNOT_BE_CLONEABLE by error0(SourceElementPositioningStrategies.INLINE_OR_VALUE_MODIFIER) val VALUE_OBJECT_NOT_SEALED_INLINE_CHILD by error0(SourceElementPositioningStrategies.INLINE_OR_VALUE_MODIFIER) + val SEALED_INLINE_CLASS_WITH_UNDERLYING_VALUE by error0(SourceElementPositioningStrategies.INLINE_OR_VALUE_MODIFIER) val SEALED_INLINE_CHILD_NOT_VALUE by error0() val SEALED_INLINE_CHILD_OVERLAPPING_TYPE by error0(SourceElementPositioningStrategies.INLINE_OR_VALUE_MODIFIER) diff --git a/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/checkers/declaration/FirInlineClassDeclarationChecker.kt b/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/checkers/declaration/FirInlineClassDeclarationChecker.kt index 923e28fd69d94..1d0f907af81c8 100644 --- a/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/checkers/declaration/FirInlineClassDeclarationChecker.kt +++ b/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/checkers/declaration/FirInlineClassDeclarationChecker.kt @@ -178,6 +178,14 @@ object FirInlineClassDeclarationChecker : FirRegularClassChecker() { } } + if (declaration.modality == Modality.SEALED && + context.languageVersionSettings.supportsFeature(LanguageFeature.SealedInlineClasses) && + primaryConstructor?.source?.kind is KtRealSourceElementKind + ) { + reporter.reportOn(declaration.source, FirErrors.SEALED_INLINE_CLASS_WITH_UNDERLYING_VALUE, context) + return + } + if (primaryConstructor == null) return for ((name, primaryConstructorParameter) in primaryConstructorParametersByName) { diff --git a/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/diagnostics/FirErrorsDefaultMessages.kt b/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/diagnostics/FirErrorsDefaultMessages.kt index bf863d62aee07..e903a9126b005 100644 --- a/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/diagnostics/FirErrorsDefaultMessages.kt +++ b/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/diagnostics/FirErrorsDefaultMessages.kt @@ -461,6 +461,7 @@ import org.jetbrains.kotlin.fir.analysis.diagnostics.FirErrors.SEALED_INHERITOR_ import org.jetbrains.kotlin.fir.analysis.diagnostics.FirErrors.SEALED_INHERITOR_IN_DIFFERENT_PACKAGE import org.jetbrains.kotlin.fir.analysis.diagnostics.FirErrors.SEALED_INLINE_CHILD_NOT_VALUE import org.jetbrains.kotlin.fir.analysis.diagnostics.FirErrors.SEALED_INLINE_CHILD_OVERLAPPING_TYPE +import org.jetbrains.kotlin.fir.analysis.diagnostics.FirErrors.SEALED_INLINE_CLASS_WITH_UNDERLYING_VALUE import org.jetbrains.kotlin.fir.analysis.diagnostics.FirErrors.SEALED_SUPERTYPE import org.jetbrains.kotlin.fir.analysis.diagnostics.FirErrors.SEALED_SUPERTYPE_IN_LOCAL_CLASS import org.jetbrains.kotlin.fir.analysis.diagnostics.FirErrors.SECONDARY_CONSTRUCTOR_WITH_BODY_INSIDE_VALUE_CLASS @@ -1241,6 +1242,7 @@ object FirErrorsDefaultMessages : BaseDiagnosticRendererFactory() { map.put(VALUE_OBJECT_NOT_SEALED_INLINE_CHILD, "value object must be child of sealed inline class") map.put(SEALED_INLINE_CHILD_NOT_VALUE, "child of sealed inline class must be value"); map.put(SEALED_INLINE_CHILD_OVERLAPPING_TYPE, "Sealed inline class child cannot be distinguished from another one"); + map.put(SEALED_INLINE_CLASS_WITH_UNDERLYING_VALUE, "Sealed inline class cannot have underlying value"); // Inline map.put( diff --git a/compiler/testData/diagnostics/tests/inlineClasses/sealed-inline-class/with-value.fir.kt b/compiler/testData/diagnostics/tests/inlineClasses/sealed-inline-class/with-value.fir.kt index 148da41e54aa4..025b5932ee719 100644 --- a/compiler/testData/diagnostics/tests/inlineClasses/sealed-inline-class/with-value.fir.kt +++ b/compiler/testData/diagnostics/tests/inlineClasses/sealed-inline-class/with-value.fir.kt @@ -6,4 +6,4 @@ package kotlin.jvm annotation class JvmInline @JvmInline -sealed value class Result(val value: Any) \ No newline at end of file +sealed value class Result(val value: Any)