diff --git a/compiler/fir/analysis-tests/testData/resolve/arguments/destructuring.kt b/compiler/fir/analysis-tests/testData/resolve/arguments/destructuring.kt index fdf3028d656..9bbfc169681 100644 --- a/compiler/fir/analysis-tests/testData/resolve/arguments/destructuring.kt +++ b/compiler/fir/analysis-tests/testData/resolve/arguments/destructuring.kt @@ -6,8 +6,8 @@ fun foo2(block: (C, C) -> Unit) = block(C(0, ""), C(0, "")) fun test() { foo1 { (x, y) -> C(x, y) } foo1 { (x: Int, y: String) -> C(x, y) } - foo1 { (x: String, y: Int) -> C(x, y) } + foo1 { (x: String, y: Int) -> C(x, y) } foo2 { (x, y), (z, w) -> C(x + z, y + w) } foo2 { (x: Int, y: String), (z: Int, w: String) -> C(x + z, y + w) } - foo2 { (x: String, y: Int), (z: String, w: Int) -> C(x + z, y + w) } + foo2 { (x: String, y: Int), (z: String, w: Int) -> C(x + z, y + w) } } diff --git a/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/FirOldFrontendDiagnosticsTestGenerated.java b/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/FirOldFrontendDiagnosticsTestGenerated.java index 99f91a15195..c23e0ef85f3 100644 --- a/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/FirOldFrontendDiagnosticsTestGenerated.java +++ b/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/FirOldFrontendDiagnosticsTestGenerated.java @@ -28811,6 +28811,12 @@ public class FirOldFrontendDiagnosticsTestGenerated extends AbstractFirDiagnosti runTest("compiler/testData/diagnostics/tests/typeParameters/deprecatedSyntax.kt"); } + @Test + @TestMetadata("destructuringDeclarations.kt") + public void testDestructuringDeclarations() throws Exception { + runTest("compiler/testData/diagnostics/tests/typeParameters/destructuringDeclarations.kt"); + } + @Test @TestMetadata("dontIntersectUpperBoundWithExpectedType.kt") public void testDontIntersectUpperBoundWithExpectedType() throws Exception { 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 e17da9a11f5..b8e021cef6f 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 @@ -508,12 +508,14 @@ object DIAGNOSTICS_LIST : DiagnosticList() { parameter("functionWithAmbiguityName") parameter>>("candidates") } - val COMPONENT_FUNCTION_ON_NULLABLE by error { parameter("componentFunctionName") } - - // TODO: val COMPONENT_FUNCTION_RETURN_TYPE_MISMATCH by ... + val COMPONENT_FUNCTION_RETURN_TYPE_MISMATCH by error { + parameter("componentFunctionName") + parameter("destructingType") + parameter("expectedType") + } } val CONTROL_FLOW by object : DiagnosticGroup("Control flow diagnostics") { 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 7f43601add9..be0ac5b710c 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 @@ -315,6 +315,7 @@ object FirErrors { val COMPONENT_FUNCTION_MISSING by error2() val COMPONENT_FUNCTION_AMBIGUITY by error2>>() val COMPONENT_FUNCTION_ON_NULLABLE by error1() + val COMPONENT_FUNCTION_RETURN_TYPE_MISMATCH by error3() // Control flow diagnostics val UNINITIALIZED_VARIABLE by error1() diff --git a/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/checkers/declaration/FirDestructuringDeclarationChecker.kt b/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/checkers/declaration/FirDestructuringDeclarationChecker.kt index a4e2600f6f4..d0d469cd08a 100644 --- a/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/checkers/declaration/FirDestructuringDeclarationChecker.kt +++ b/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/checkers/declaration/FirDestructuringDeclarationChecker.kt @@ -24,9 +24,9 @@ import org.jetbrains.kotlin.fir.resolve.diagnostics.ConeAmbiguityError import org.jetbrains.kotlin.fir.resolve.diagnostics.ConeInapplicableCandidateError import org.jetbrains.kotlin.fir.resolve.diagnostics.ConeUnresolvedNameError import org.jetbrains.kotlin.fir.symbols.impl.FirVariableSymbol -import org.jetbrains.kotlin.fir.types.ConeKotlinType -import org.jetbrains.kotlin.fir.types.coneTypeSafe -import org.jetbrains.kotlin.fir.types.isNullable +import org.jetbrains.kotlin.fir.typeContext +import org.jetbrains.kotlin.fir.types.* +import org.jetbrains.kotlin.types.AbstractTypeChecker object FirDestructuringDeclarationChecker : FirPropertyChecker() { override fun check(declaration: FirProperty, context: CheckerContext, reporter: DiagnosticReporter) { @@ -44,8 +44,6 @@ object FirDestructuringDeclarationChecker : FirPropertyChecker() { if (source.elementType != KtNodeTypes.DESTRUCTURING_DECLARATION_ENTRY) return val componentCall = declaration.initializer as? FirComponentCall ?: return - val reference = componentCall.calleeReference as? FirErrorNamedReference ?: return - val originalExpression = componentCall.explicitReceiverOfQualifiedAccess ?: return val originalDestructuringDeclaration = originalExpression.resolvedVariable ?: return val originalDestructuringDeclarationOrInitializer = @@ -75,39 +73,25 @@ object FirDestructuringDeclarationChecker : FirPropertyChecker() { else -> null } ?: return - when (val diagnostic = reference.diagnostic) { - is ConeUnresolvedNameError -> { - reporter.report( - FirErrors.COMPONENT_FUNCTION_MISSING.on( - originalDestructuringDeclarationOrInitializerSource, - diagnostic.name, - originalDestructuringDeclarationType - ), + when (val reference = componentCall.calleeReference) { + is FirResolvedNamedReference -> + checkComponentCallReturnType( + originalDestructuringDeclarationOrInitializerSource, + declaration, + componentCall, + originalDestructuringDeclaration, + reference, + reporter, context ) - } - is ConeAmbiguityError -> { - reporter.report( - FirErrors.COMPONENT_FUNCTION_AMBIGUITY.on( - originalDestructuringDeclarationOrInitializerSource, - diagnostic.name, - diagnostic.candidates - ), + is FirErrorNamedReference -> + checkComponentCall( + originalDestructuringDeclarationOrInitializerSource, + originalDestructuringDeclarationType, + reference, + reporter, context ) - } - is ConeInapplicableCandidateError -> { - if (originalDestructuringDeclarationType.isNullable) { - reporter.report( - FirErrors.COMPONENT_FUNCTION_ON_NULLABLE.on( - originalDestructuringDeclarationOrInitializerSource, - (diagnostic.candidate.symbol.fir as FirSimpleFunction).name - ), - context - ) - } - } - // TODO: COMPONENT_FUNCTION_RETURN_TYPE_MISMATCH } } @@ -128,6 +112,79 @@ object FirDestructuringDeclarationChecker : FirPropertyChecker() { } } + private fun checkComponentCallReturnType( + source: FirSourceElement, + property: FirProperty, + componentCall: FirComponentCall, + destructuringDeclaration: FirVariable<*>, + reference: FirResolvedNamedReference, + reporter: DiagnosticReporter, + context: CheckerContext + ) { + val destructuringType = componentCall.typeRef.coneType + if (destructuringType is ConeKotlinErrorType) { + // There will be other errors on this error type. + return + } + val expectedType = property.returnTypeRef.coneType + if (!AbstractTypeChecker.isSubtypeOf(context.session.typeContext, destructuringType, expectedType)) { + val typeMismatchSource = + // ... = { `(entry, ...)` -> ... } // Report on specific `entry` + if (destructuringDeclaration is FirValueParameter) + property.source + // val (entry, ...) = `destructuring_declaration` // Report on a destructuring declaration + else + source + reporter.reportOn( + typeMismatchSource, + FirErrors.COMPONENT_FUNCTION_RETURN_TYPE_MISMATCH, + (reference.resolvedSymbol.fir as FirSimpleFunction).name, + destructuringType, + expectedType, + context + ) + } + } + + private fun checkComponentCall( + source: FirSourceElement, + destructuringDeclarationType: ConeKotlinType, + reference: FirErrorNamedReference, + reporter: DiagnosticReporter, + context: CheckerContext + ) { + when (val diagnostic = reference.diagnostic) { + is ConeUnresolvedNameError -> { + reporter.reportOn( + source, + FirErrors.COMPONENT_FUNCTION_MISSING, + diagnostic.name, + destructuringDeclarationType, + context + ) + } + is ConeAmbiguityError -> { + reporter.reportOn( + source, + FirErrors.COMPONENT_FUNCTION_AMBIGUITY, + diagnostic.name, + diagnostic.candidates, + context + ) + } + is ConeInapplicableCandidateError -> { + if (destructuringDeclarationType.isNullable) { + reporter.reportOn( + source, + FirErrors.COMPONENT_FUNCTION_ON_NULLABLE, + (diagnostic.candidate.symbol.fir as FirSimpleFunction).name, + context + ) + } + } + } + } + private val FirExpression.explicitReceiverOfQualifiedAccess: FirQualifiedAccessExpression? get() = (this as? FirQualifiedAccess)?.explicitReceiver?.unwrapped as? FirQualifiedAccessExpression diff --git a/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/collectors/components/ErrorNodeDiagnosticCollectorComponent.kt b/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/collectors/components/ErrorNodeDiagnosticCollectorComponent.kt index ca290950888..d6029bc8bf8 100644 --- a/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/collectors/components/ErrorNodeDiagnosticCollectorComponent.kt +++ b/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/collectors/components/ErrorNodeDiagnosticCollectorComponent.kt @@ -82,15 +82,8 @@ class ErrorNodeDiagnosticCollectorComponent(collector: AbstractDiagnosticCollect ) { // Will be handled by [FirDestructuringDeclarationChecker] if (source.elementType == KtNodeTypes.DESTRUCTURING_DECLARATION_ENTRY) { - // TODO: if all diagnostics are supported, we don't need the following check, and will bail out based on element type. - if (diagnostic is ConeUnresolvedNameError || - diagnostic is ConeAmbiguityError || - diagnostic is ConeInapplicableCandidateError - ) { - return - } + return } - if (source.kind == FirFakeSourceElementKind.ImplicitConstructor) { return } diff --git a/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/diagnostics/FirDefaultErrorMessages.kt b/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/diagnostics/FirDefaultErrorMessages.kt index ea45b52a744..f3585c62a4a 100644 --- a/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/diagnostics/FirDefaultErrorMessages.kt +++ b/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/diagnostics/FirDefaultErrorMessages.kt @@ -56,6 +56,7 @@ import org.jetbrains.kotlin.fir.analysis.diagnostics.FirErrors.CLASS_LITERAL_LHS import org.jetbrains.kotlin.fir.analysis.diagnostics.FirErrors.COMPONENT_FUNCTION_AMBIGUITY import org.jetbrains.kotlin.fir.analysis.diagnostics.FirErrors.COMPONENT_FUNCTION_MISSING import org.jetbrains.kotlin.fir.analysis.diagnostics.FirErrors.COMPONENT_FUNCTION_ON_NULLABLE +import org.jetbrains.kotlin.fir.analysis.diagnostics.FirErrors.COMPONENT_FUNCTION_RETURN_TYPE_MISMATCH import org.jetbrains.kotlin.fir.analysis.diagnostics.FirErrors.CONFLICTING_OVERLOADS import org.jetbrains.kotlin.fir.analysis.diagnostics.FirErrors.CONFLICTING_PROJECTION import org.jetbrains.kotlin.fir.analysis.diagnostics.FirErrors.CONFLICTING_UPPER_BOUNDS @@ -695,6 +696,13 @@ class FirDefaultErrorMessages : DefaultErrorMessages.Extension { "Not nullable value required to call ''{0}()'' function of destructuring declaration initializer", TO_STRING ) + map.put( + COMPONENT_FUNCTION_RETURN_TYPE_MISMATCH, + "''{0}()'' function returns ''{1}'', but ''{2}'' is expected", + TO_STRING, + RENDER_TYPE, + RENDER_TYPE + ) // Control flow diagnostics map.put(UNINITIALIZED_VARIABLE, "{0} must be initialized before access", VARIABLE_NAME) diff --git a/compiler/testData/diagnostics/tests/callableReference/generic/genericFunctionsWithNullableTypes.fir.kt b/compiler/testData/diagnostics/tests/callableReference/generic/genericFunctionsWithNullableTypes.fir.kt index fc0a7eb3a4e..092be2981f6 100644 --- a/compiler/testData/diagnostics/tests/callableReference/generic/genericFunctionsWithNullableTypes.fir.kt +++ b/compiler/testData/diagnostics/tests/callableReference/generic/genericFunctionsWithNullableTypes.fir.kt @@ -33,5 +33,5 @@ fun test(x: T) { val s4: Pair = bar(null, null, ::foo) val s5: Pair = bar(1, "", ::foo) - val (a1: Int, b1: String) = bar(1, "", ::foo) + val (a1: Int, b1: String) = bar(1, "", ::foo) } diff --git a/compiler/testData/diagnostics/tests/declarationChecks/ComponentFunctionReturnTypeMismatch.fir.kt b/compiler/testData/diagnostics/tests/declarationChecks/ComponentFunctionReturnTypeMismatch.fir.kt deleted file mode 100644 index e8bc3635afa..00000000000 --- a/compiler/testData/diagnostics/tests/declarationChecks/ComponentFunctionReturnTypeMismatch.fir.kt +++ /dev/null @@ -1,9 +0,0 @@ -// !WITH_NEW_INFERENCE -class A { - operator fun component1() : Int = 1 - operator fun component2() : Int = 2 -} - -fun a(aa : A) { - val (a: String, b1: String) = aa -} diff --git a/compiler/testData/diagnostics/tests/declarationChecks/ComponentFunctionReturnTypeMismatch.kt b/compiler/testData/diagnostics/tests/declarationChecks/ComponentFunctionReturnTypeMismatch.kt index d06ff5a7dfa..27d2ca97ea2 100644 --- a/compiler/testData/diagnostics/tests/declarationChecks/ComponentFunctionReturnTypeMismatch.kt +++ b/compiler/testData/diagnostics/tests/declarationChecks/ComponentFunctionReturnTypeMismatch.kt @@ -1,3 +1,4 @@ +// FIR_IDENTICAL // !WITH_NEW_INFERENCE class A { operator fun component1() : Int = 1 diff --git a/compiler/testData/diagnostics/tests/declarationChecks/destructuringDeclarations/FolLoopTypeComponentTypeMismatch.fir.kt b/compiler/testData/diagnostics/tests/declarationChecks/destructuringDeclarations/FolLoopTypeComponentTypeMismatch.fir.kt deleted file mode 100644 index bbbf1fca597..00000000000 --- a/compiler/testData/diagnostics/tests/declarationChecks/destructuringDeclarations/FolLoopTypeComponentTypeMismatch.fir.kt +++ /dev/null @@ -1,15 +0,0 @@ -// !WITH_NEW_INFERENCE -class A { - operator fun component1() = 1 - operator fun component2() = 1.0 -} - -class C { - operator fun iterator(): Iterator = null!! -} - -fun test() { - for ((x: Double, y: Int) in C()) { - - } -} diff --git a/compiler/testData/diagnostics/tests/declarationChecks/destructuringDeclarations/FolLoopTypeComponentTypeMismatch.kt b/compiler/testData/diagnostics/tests/declarationChecks/destructuringDeclarations/FolLoopTypeComponentTypeMismatch.kt index c42675247ef..bd7ebbd32e9 100644 --- a/compiler/testData/diagnostics/tests/declarationChecks/destructuringDeclarations/FolLoopTypeComponentTypeMismatch.kt +++ b/compiler/testData/diagnostics/tests/declarationChecks/destructuringDeclarations/FolLoopTypeComponentTypeMismatch.kt @@ -1,3 +1,4 @@ +// FIR_IDENTICAL // !WITH_NEW_INFERENCE class A { operator fun component1() = 1 diff --git a/compiler/testData/diagnostics/tests/functionLiterals/destructuringInLambdas/inferredFunctionalType.fir.kt b/compiler/testData/diagnostics/tests/functionLiterals/destructuringInLambdas/inferredFunctionalType.fir.kt index 0fcfc1b4a2d..651b8a2da93 100644 --- a/compiler/testData/diagnostics/tests/functionLiterals/destructuringInLambdas/inferredFunctionalType.fir.kt +++ b/compiler/testData/diagnostics/tests/functionLiterals/destructuringInLambdas/inferredFunctionalType.fir.kt @@ -22,7 +22,7 @@ fun bar(aList: List) { b checkType { _() } } - aList.foo { (a: String, b) -> + aList.foo { (a: String, b) -> a checkType { _() } b checkType { _() } } diff --git a/compiler/testData/diagnostics/tests/functionLiterals/destructuringInLambdas/simple.fir.kt b/compiler/testData/diagnostics/tests/functionLiterals/destructuringInLambdas/simple.fir.kt index 18a810c9305..9e5d80c551f 100644 --- a/compiler/testData/diagnostics/tests/functionLiterals/destructuringInLambdas/simple.fir.kt +++ b/compiler/testData/diagnostics/tests/functionLiterals/destructuringInLambdas/simple.fir.kt @@ -42,7 +42,7 @@ fun bar() { d checkType { _() } } - foo { (a: String, b) -> + foo { (a: String, b) -> a checkType { _() } b checkType { _() } } diff --git a/compiler/testData/diagnostics/tests/typeParameters/destructuringDeclarations.kt b/compiler/testData/diagnostics/tests/typeParameters/destructuringDeclarations.kt new file mode 100644 index 00000000000..b837c01fad9 --- /dev/null +++ b/compiler/testData/diagnostics/tests/typeParameters/destructuringDeclarations.kt @@ -0,0 +1,16 @@ +// FIR_IDENTICAL +data class A(val i: T) + +fun foo(block: (A) -> Unit) {} + +fun bar() { + foo { (i: T) -> + i + } +} + +data class C(val x: Int, val y: T) + +fun foo(c: C) { + val (x: Int, y: S) = c +} diff --git a/compiler/testData/diagnostics/tests/typeParameters/destructuringDeclarations.txt b/compiler/testData/diagnostics/tests/typeParameters/destructuringDeclarations.txt new file mode 100644 index 00000000000..72e57428ee5 --- /dev/null +++ b/compiler/testData/diagnostics/tests/typeParameters/destructuringDeclarations.txt @@ -0,0 +1,27 @@ +package + +public fun bar(): kotlin.Unit +public fun foo(/*0*/ block: (A) -> kotlin.Unit): kotlin.Unit +public fun foo(/*0*/ c: C): kotlin.Unit + +public final data class A { + public constructor A(/*0*/ i: T) + public final val i: T + public final operator /*synthesized*/ fun component1(): T + public final /*synthesized*/ fun copy(/*0*/ i: T = ...): A + public open override /*1*/ /*synthesized*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean + public open override /*1*/ /*synthesized*/ fun hashCode(): kotlin.Int + public open override /*1*/ /*synthesized*/ fun toString(): kotlin.String +} + +public final data class C { + public constructor C(/*0*/ x: kotlin.Int, /*1*/ y: T) + public final val x: kotlin.Int + public final val y: T + public final operator /*synthesized*/ fun component1(): kotlin.Int + public final operator /*synthesized*/ fun component2(): T + public final /*synthesized*/ fun copy(/*0*/ x: kotlin.Int = ..., /*1*/ y: T = ...): C + public open override /*1*/ /*synthesized*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean + public open override /*1*/ /*synthesized*/ fun hashCode(): kotlin.Int + public open override /*1*/ /*synthesized*/ fun toString(): kotlin.String +} diff --git a/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/DiagnosticTestGenerated.java b/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/DiagnosticTestGenerated.java index 70838edc17b..6e18e7c6bbb 100644 --- a/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/DiagnosticTestGenerated.java +++ b/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/DiagnosticTestGenerated.java @@ -28907,6 +28907,12 @@ public class DiagnosticTestGenerated extends AbstractDiagnosticTest { runTest("compiler/testData/diagnostics/tests/typeParameters/deprecatedSyntax.kt"); } + @Test + @TestMetadata("destructuringDeclarations.kt") + public void testDestructuringDeclarations() throws Exception { + runTest("compiler/testData/diagnostics/tests/typeParameters/destructuringDeclarations.kt"); + } + @Test @TestMetadata("dontIntersectUpperBoundWithExpectedType.kt") public void testDontIntersectUpperBoundWithExpectedType() throws Exception { diff --git a/idea/idea-frontend-fir/src/org/jetbrains/kotlin/idea/frontend/api/fir/diagnostics/KtFirDataClassConverters.kt b/idea/idea-frontend-fir/src/org/jetbrains/kotlin/idea/frontend/api/fir/diagnostics/KtFirDataClassConverters.kt index e0680a22a23..a86563d47e1 100644 --- a/idea/idea-frontend-fir/src/org/jetbrains/kotlin/idea/frontend/api/fir/diagnostics/KtFirDataClassConverters.kt +++ b/idea/idea-frontend-fir/src/org/jetbrains/kotlin/idea/frontend/api/fir/diagnostics/KtFirDataClassConverters.kt @@ -1444,6 +1444,15 @@ internal val KT_DIAGNOSTIC_CONVERTER = KtDiagnosticConverterBuilder.buildConvert token, ) } + add(FirErrors.COMPONENT_FUNCTION_RETURN_TYPE_MISMATCH) { firDiagnostic -> + ComponentFunctionReturnTypeMismatchImpl( + firDiagnostic.a, + firSymbolBuilder.typeBuilder.buildKtType(firDiagnostic.b), + firSymbolBuilder.typeBuilder.buildKtType(firDiagnostic.c), + firDiagnostic as FirPsiDiagnostic<*>, + token, + ) + } add(FirErrors.UNINITIALIZED_VARIABLE) { firDiagnostic -> UninitializedVariableImpl( firSymbolBuilder.variableLikeBuilder.buildVariableSymbol(firDiagnostic.a.fir as FirProperty), diff --git a/idea/idea-frontend-fir/src/org/jetbrains/kotlin/idea/frontend/api/fir/diagnostics/KtFirDiagnostics.kt b/idea/idea-frontend-fir/src/org/jetbrains/kotlin/idea/frontend/api/fir/diagnostics/KtFirDiagnostics.kt index 910234cba52..bac1fced1d4 100644 --- a/idea/idea-frontend-fir/src/org/jetbrains/kotlin/idea/frontend/api/fir/diagnostics/KtFirDiagnostics.kt +++ b/idea/idea-frontend-fir/src/org/jetbrains/kotlin/idea/frontend/api/fir/diagnostics/KtFirDiagnostics.kt @@ -1020,6 +1020,13 @@ sealed class KtFirDiagnostic : KtDiagnosticWithPsi { abstract val componentFunctionName: Name } + abstract class ComponentFunctionReturnTypeMismatch : KtFirDiagnostic() { + override val diagnosticClass get() = ComponentFunctionReturnTypeMismatch::class + abstract val componentFunctionName: Name + abstract val destructingType: KtType + abstract val expectedType: KtType + } + abstract class UninitializedVariable : KtFirDiagnostic() { override val diagnosticClass get() = UninitializedVariable::class abstract val variable: KtVariableSymbol diff --git a/idea/idea-frontend-fir/src/org/jetbrains/kotlin/idea/frontend/api/fir/diagnostics/KtFirDiagnosticsImpl.kt b/idea/idea-frontend-fir/src/org/jetbrains/kotlin/idea/frontend/api/fir/diagnostics/KtFirDiagnosticsImpl.kt index 94abfe7054a..ccebe1c4dd1 100644 --- a/idea/idea-frontend-fir/src/org/jetbrains/kotlin/idea/frontend/api/fir/diagnostics/KtFirDiagnosticsImpl.kt +++ b/idea/idea-frontend-fir/src/org/jetbrains/kotlin/idea/frontend/api/fir/diagnostics/KtFirDiagnosticsImpl.kt @@ -1651,6 +1651,16 @@ internal class ComponentFunctionOnNullableImpl( override val firDiagnostic: FirPsiDiagnostic<*> by weakRef(firDiagnostic) } +internal class ComponentFunctionReturnTypeMismatchImpl( + override val componentFunctionName: Name, + override val destructingType: KtType, + override val expectedType: KtType, + firDiagnostic: FirPsiDiagnostic<*>, + override val token: ValidityToken, +) : KtFirDiagnostic.ComponentFunctionReturnTypeMismatch(), KtAbstractFirDiagnostic { + override val firDiagnostic: FirPsiDiagnostic<*> by weakRef(firDiagnostic) +} + internal class UninitializedVariableImpl( override val variable: KtVariableSymbol, firDiagnostic: FirPsiDiagnostic<*>,