From 36c9418d55e68d605802154cd21c9b91acdd2dde Mon Sep 17 00:00:00 2001 From: "Denis.Zharkov" Date: Wed, 19 May 2021 18:21:00 +0300 Subject: [PATCH] FIR: Convert couple of methods to block-body --- .../coneDiagnosticToFirDiagnostic.kt | 100 +++++++++--------- 1 file changed, 52 insertions(+), 48 deletions(-) diff --git a/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/diagnostics/coneDiagnosticToFirDiagnostic.kt b/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/diagnostics/coneDiagnosticToFirDiagnostic.kt index 2dbd5452ec2..2662585e73f 100644 --- a/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/diagnostics/coneDiagnosticToFirDiagnostic.kt +++ b/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/diagnostics/coneDiagnosticToFirDiagnostic.kt @@ -163,66 +163,70 @@ private fun mapSystemHasContradictionError( diagnostic: ConeConstraintSystemHasContradiction, source: FirSourceElement, qualifiedAccessSource: FirSourceElement?, -): List> = buildList> { - for (error in diagnostic.candidate.system.errors) { - addIfNotNull(error.toDiagnostic(source, qualifiedAccessSource, diagnostic.candidate.callInfo.session.typeContext)) - } -}.ifEmpty { - listOfNotNull( - diagnostic.candidate.system.errors.firstNotNullOfOrNull { - val message = when (it) { - is NewConstraintError -> "NewConstraintError at ${it.position}: ${it.lowerType} return@firstNotNullOfOrNull null - else -> "Inference error: ${it::class.simpleName}" - } - FirErrors.NEW_INFERENCE_ERROR.on(qualifiedAccessSource ?: source, message) +): List> { + return buildList> { + for (error in diagnostic.candidate.system.errors) { + addIfNotNull(error.toDiagnostic(source, qualifiedAccessSource, diagnostic.candidate.callInfo.session.typeContext)) } - ) + }.ifEmpty { + listOfNotNull( + diagnostic.candidate.system.errors.firstNotNullOfOrNull { + val message = when (it) { + is NewConstraintError -> "NewConstraintError at ${it.position}: ${it.lowerType} return@firstNotNullOfOrNull null + else -> "Inference error: ${it::class.simpleName}" + } + FirErrors.NEW_INFERENCE_ERROR.on(qualifiedAccessSource ?: source, message) + } + ) + } } private fun ConstraintSystemError.toDiagnostic( source: FirSourceElement, qualifiedAccessSource: FirSourceElement?, typeContext: ConeTypeContext, -): FirDiagnostic? = when (this) { - is NewConstraintError -> { - val position = position.from - val argument = +): FirDiagnostic? { + return when (this) { + is NewConstraintError -> { + val position = position.from + val argument = + when (position) { + // TODO: Support other ReceiverConstraintPositionImpl, LHSArgumentConstraintPositionImpl + is ConeArgumentConstraintPosition -> position.argument + is ConeLambdaArgumentConstraintPosition -> position.lambda + else -> null + } + + argument?.let { + return FirErrors.TYPE_MISMATCH.on(it.source ?: source, lowerConeType, upperConeType) + } + when (position) { - // TODO: Support other ReceiverConstraintPositionImpl, LHSArgumentConstraintPositionImpl - is ConeArgumentConstraintPosition -> position.argument - is ConeLambdaArgumentConstraintPosition -> position.lambda + is ExpectedTypeConstraintPosition<*> -> { + val inferredType = + if (!lowerConeType.isNullableNothing) + lowerConeType + else + upperConeType.withNullability(ConeNullability.NULLABLE, typeContext) + + FirErrors.TYPE_MISMATCH.on(qualifiedAccessSource ?: source, upperConeType, inferredType) + } + is ExplicitTypeParameterConstraintPosition<*> -> { + val conePosition = position as ConeExplicitTypeParameterConstraintPosition + val typeArgument = conePosition.typeArgument + + FirErrors.UPPER_BOUND_VIOLATED.on( + typeArgument.source ?: qualifiedAccessSource ?: source, + upperConeType, + ) + } else -> null } - - argument?.let { - return FirErrors.TYPE_MISMATCH.on(it.source ?: source, lowerConeType, upperConeType) - } - - when (position) { - is ExpectedTypeConstraintPosition<*> -> { - val inferredType = - if (!lowerConeType.isNullableNothing) - lowerConeType - else - upperConeType.withNullability(ConeNullability.NULLABLE, typeContext) - - FirErrors.TYPE_MISMATCH.on(qualifiedAccessSource ?: source, upperConeType, inferredType) - } - is ExplicitTypeParameterConstraintPosition<*> -> { - val conePosition = position as ConeExplicitTypeParameterConstraintPosition - val typeArgument = conePosition.typeArgument - - FirErrors.UPPER_BOUND_VIOLATED.on( - typeArgument.source ?: qualifiedAccessSource ?: source, - upperConeType, - ) - } - else -> null } + else -> null } - else -> null } private val NewConstraintError.lowerConeType: ConeKotlinType get() = lowerType as ConeKotlinType