Minor. Cleanup diagnosticForArgumentTypeMismatch
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 141be0d..3b45d8c 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
@@ -314,6 +314,7 @@
diagnostic.candidate,
typeContext,
),
+ // For lambda expressions, use their resolved type because `rootCause.actualType` can contain unresolved types
actualType = if (rootCause.argument is FirAnonymousFunctionExpression && !rootCause.argument.resolvedType.hasError()) {
rootCause.argument.resolvedType
} else {
@@ -476,22 +477,19 @@
val symbol = candidate.symbol as FirCallableSymbol
val receiverType = (candidate.chosenExtensionReceiver ?: candidate.dispatchReceiver)?.expression?.resolvedType
- return if (expectedType is ConeCapturedType &&
- expectedType.constructor.projection.kind.let { it == ProjectionKind.OUT || it == ProjectionKind.STAR } &&
- receiverType != null &&
- // Ensure we report an actual argument type mismatch of the candidate and not a lambda return expression
- candidate.argumentMapping.keys.any { it.expression.source == source }
- ) {
- FirErrors.MEMBER_PROJECTED_OUT.createOn(
+ return when {
+ expectedType is ConeCapturedType && expectedType.isBasedOnStarOrOut() && receiverType != null &&
+ // Ensure we report an actual argument type mismatch of the candidate and not a lambda return expression
+ candidate.argumentMapping.keys.any { it.expression.source == source }
+ ->
+ FirErrors.MEMBER_PROJECTED_OUT.createOn(
+ source,
+ receiverType,
+ expectedType.projectionKindAsString(),
+ symbol.originalOrSelf(),
+ )
+ else -> FirErrors.ARGUMENT_TYPE_MISMATCH.createOn(
source,
- receiverType,
- expectedType.projectionKindAsString(),
- symbol.originalOrSelf(),
- )
- } else {
- FirErrors.ARGUMENT_TYPE_MISMATCH.createOn(
- source,
- // For lambda expressions, use their resolved type because `rootCause.actualType` can contain unresolved types
actualType,
expectedType,
isMismatchDueToNullability
@@ -499,6 +497,9 @@
}
}
+private fun ConeCapturedType.isBasedOnStarOrOut(): Boolean =
+ constructor.projection.kind.let { it == ProjectionKind.OUT || it == ProjectionKind.STAR }
+
private fun UnstableSmartCast.mapUnstableSmartCast(): KtDiagnosticWithParameters4<ConeKotlinType, FirExpression, String, Boolean> {
val factory = when {
isImplicitInvokeReceiver -> FirErrors.SMARTCAST_IMPOSSIBLE_ON_IMPLICIT_INVOKE_RECEIVER