FIR: Convert couple of methods to block-body
This commit is contained in:
committed by
teamcityserver
parent
7c05c6420a
commit
36c9418d55
+52
-48
@@ -163,66 +163,70 @@ private fun mapSystemHasContradictionError(
|
|||||||
diagnostic: ConeConstraintSystemHasContradiction,
|
diagnostic: ConeConstraintSystemHasContradiction,
|
||||||
source: FirSourceElement,
|
source: FirSourceElement,
|
||||||
qualifiedAccessSource: FirSourceElement?,
|
qualifiedAccessSource: FirSourceElement?,
|
||||||
): List<FirDiagnostic<FirSourceElement>> = buildList<FirDiagnostic<FirSourceElement>> {
|
): List<FirDiagnostic<FirSourceElement>> {
|
||||||
for (error in diagnostic.candidate.system.errors) {
|
return buildList<FirDiagnostic<FirSourceElement>> {
|
||||||
addIfNotNull(error.toDiagnostic(source, qualifiedAccessSource, diagnostic.candidate.callInfo.session.typeContext))
|
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} <!: ${it.upperType}"
|
|
||||||
// Error should be reported on the error type itself
|
|
||||||
is ConstrainingTypeIsError -> return@firstNotNullOfOrNull null
|
|
||||||
else -> "Inference error: ${it::class.simpleName}"
|
|
||||||
}
|
|
||||||
FirErrors.NEW_INFERENCE_ERROR.on(qualifiedAccessSource ?: source, message)
|
|
||||||
}
|
}
|
||||||
)
|
}.ifEmpty {
|
||||||
|
listOfNotNull(
|
||||||
|
diagnostic.candidate.system.errors.firstNotNullOfOrNull {
|
||||||
|
val message = when (it) {
|
||||||
|
is NewConstraintError -> "NewConstraintError at ${it.position}: ${it.lowerType} <!: ${it.upperType}"
|
||||||
|
// Error should be reported on the error type itself
|
||||||
|
is ConstrainingTypeIsError -> return@firstNotNullOfOrNull null
|
||||||
|
else -> "Inference error: ${it::class.simpleName}"
|
||||||
|
}
|
||||||
|
FirErrors.NEW_INFERENCE_ERROR.on(qualifiedAccessSource ?: source, message)
|
||||||
|
}
|
||||||
|
)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun ConstraintSystemError.toDiagnostic(
|
private fun ConstraintSystemError.toDiagnostic(
|
||||||
source: FirSourceElement,
|
source: FirSourceElement,
|
||||||
qualifiedAccessSource: FirSourceElement?,
|
qualifiedAccessSource: FirSourceElement?,
|
||||||
typeContext: ConeTypeContext,
|
typeContext: ConeTypeContext,
|
||||||
): FirDiagnostic<FirSourceElement>? = when (this) {
|
): FirDiagnostic<FirSourceElement>? {
|
||||||
is NewConstraintError -> {
|
return when (this) {
|
||||||
val position = position.from
|
is NewConstraintError -> {
|
||||||
val argument =
|
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) {
|
when (position) {
|
||||||
// TODO: Support other ReceiverConstraintPositionImpl, LHSArgumentConstraintPositionImpl
|
is ExpectedTypeConstraintPosition<*> -> {
|
||||||
is ConeArgumentConstraintPosition -> position.argument
|
val inferredType =
|
||||||
is ConeLambdaArgumentConstraintPosition -> position.lambda
|
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
|
||||||
}
|
}
|
||||||
|
|
||||||
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
|
private val NewConstraintError.lowerConeType: ConeKotlinType get() = lowerType as ConeKotlinType
|
||||||
|
|||||||
Reference in New Issue
Block a user