From c758069d7c59b517337a1f63ea496dbee04bef8b Mon Sep 17 00:00:00 2001 From: "Denis.Zharkov" Date: Tue, 27 Apr 2021 15:44:29 +0300 Subject: [PATCH] FIR: Rework reporting COMPONENT_FUNCTION_RETURN_TYPE_MISMATCH Previously, it was reported via additional check on successful calls But now it's contained within FirErrorNamedReference --- .../FirDestructuringDeclarationChecker.kt | 76 ++++++++----------- 1 file changed, 32 insertions(+), 44 deletions(-) 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 59e2807ce45..b8e50afe9bd 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 @@ -21,6 +21,7 @@ import org.jetbrains.kotlin.fir.expressions.* import org.jetbrains.kotlin.fir.references.FirErrorNamedReference import org.jetbrains.kotlin.fir.references.FirResolvedNamedReference import org.jetbrains.kotlin.fir.resolve.diagnostics.ConeAmbiguityError +import org.jetbrains.kotlin.fir.resolve.diagnostics.ConeConstraintSystemHasContradiction import org.jetbrains.kotlin.fir.resolve.diagnostics.ConeInapplicableCandidateError import org.jetbrains.kotlin.fir.resolve.diagnostics.ConeUnresolvedNameError import org.jetbrains.kotlin.fir.symbols.impl.FirVariableSymbol @@ -71,21 +72,14 @@ object FirDestructuringDeclarationChecker : FirPropertyChecker() { } ?: return when (val reference = componentCall.calleeReference) { - is FirResolvedNamedReference -> - checkComponentCallReturnType( - originalDestructuringDeclarationOrInitializerSource, - declaration, - componentCall, - originalDestructuringDeclaration, - reference, - reporter, - context - ) is FirErrorNamedReference -> checkComponentCall( originalDestructuringDeclarationOrInitializerSource, originalDestructuringDeclarationType, reference, + declaration, + componentCall, + originalDestructuringDeclaration, reporter, context ) @@ -109,44 +103,13 @@ 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, + property: FirProperty, + componentCall: FirComponentCall, + destructuringDeclaration: FirVariable<*>, reporter: DiagnosticReporter, context: CheckerContext ) { @@ -179,6 +142,31 @@ object FirDestructuringDeclarationChecker : FirPropertyChecker() { ) } } + is ConeConstraintSystemHasContradiction -> { + val componentType = componentCall.typeRef.coneType + if (componentType is ConeKotlinErrorType) { + // There will be other errors on this error type. + return + } + val expectedType = property.returnTypeRef.coneType + if (!AbstractTypeChecker.isSubtypeOf(context.session.typeContext, componentType, 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, + diagnostic.candidate.callInfo.name, + componentType, + expectedType, + context + ) + } + } } }