K2: Avoid inference diagnostics when arguments are already error typed

For example, NEW_INFERENCE_NO_INFORMATION_FOR_PARAMETER

It became especially relevant after 0e84bf2053
that together with later commits bring a lot of unnecessary
NEW_INFERENCE_NO_INFORMATION_FOR_PARAMETER diagnostic
This commit is contained in:
Denis.Zharkov
2022-11-30 14:20:11 +01:00
committed by Space Team
parent 564b40f05d
commit fe5adab652
33 changed files with 43 additions and 145 deletions
@@ -352,13 +352,12 @@ private fun checkApplicabilityForArgumentType(
// todo run this approximation only once for call
val argumentType = captureFromTypeParameterUpperBoundIfNeeded(argumentTypeBeforeCapturing, expectedType, context.session)
fun subtypeError(actualExpectedType: ConeKotlinType): ResolutionDiagnostic? {
fun subtypeError(actualExpectedType: ConeKotlinType): ResolutionDiagnostic {
if (argument.isNullLiteral && actualExpectedType.nullability == ConeNullability.NOT_NULL) {
return NullForNotNullType(argument)
}
fun tryGetConeTypeThatCompatibleWithKtType(type: ConeKotlinType): ConeKotlinType? {
if (type is ConeErrorType) return null
fun tryGetConeTypeThatCompatibleWithKtType(type: ConeKotlinType): ConeKotlinType {
if (type is ConeTypeVariableType) {
val lookupTag = type.lookupTag
@@ -380,8 +379,10 @@ private fun checkApplicabilityForArgumentType(
return type
}
val preparedExpectedType = tryGetConeTypeThatCompatibleWithKtType(actualExpectedType) ?: return null
val preparedActualType = tryGetConeTypeThatCompatibleWithKtType(argumentType) ?: return null
if (argumentType is ConeErrorType || actualExpectedType is ConeErrorType) return ErrorTypeInArguments
val preparedExpectedType = tryGetConeTypeThatCompatibleWithKtType(actualExpectedType)
val preparedActualType = tryGetConeTypeThatCompatibleWithKtType(argumentType)
return ArgumentTypeMismatch(
preparedExpectedType,
preparedActualType,
@@ -419,7 +420,7 @@ private fun checkApplicabilityForArgumentType(
}
if (!isReceiver) {
sink.reportDiagnosticIfNotNull(subtypeError(expectedType))
sink.reportDiagnostic(subtypeError(expectedType))
return
}