[FIR2IR] Remove argument unwrapping for SAM conversion

FirNamedArgumentExpressions don't exist anymore during FIR2IR phase
and so we don't need to unwrap arguments here anymore.

#KT-66124
This commit is contained in:
Kirill Rakhman
2024-03-04 17:36:46 +01:00
committed by Space Team
parent 015f257031
commit fbb21f2406
@@ -43,8 +43,6 @@ import org.jetbrains.kotlin.ir.expressions.impl.*
import org.jetbrains.kotlin.ir.symbols.*
import org.jetbrains.kotlin.ir.types.*
import org.jetbrains.kotlin.ir.util.dump
import org.jetbrains.kotlin.ir.util.isPrimitiveArray
import org.jetbrains.kotlin.ir.util.isUnsignedArray
import org.jetbrains.kotlin.ir.util.render
import org.jetbrains.kotlin.name.Name
import org.jetbrains.kotlin.resolve.calls.NewCommonSuperTypeCalculator.commonSuperType
@@ -1045,12 +1043,11 @@ class CallAndReferenceGenerator(
// In this case we have to use parameter type itself which is more precise, like Array<String> or IntArray.
// See KT-62598 and its fix for details.
val expectedType = unsubstitutedParameterType.takeIf { visitor.annotationMode && unsubstitutedParameterType?.isArrayType == true }
val unwrappedArgument = argument.unwrapArgument()
var irArgument = visitor.convertToIrExpression(unwrappedArgument, expectedType = expectedType)
var irArgument = visitor.convertToIrExpression(argument, expectedType = expectedType)
if (unsubstitutedParameterType != null) {
with(visitor.implicitCastInserter) {
val argumentType = unwrappedArgument.resolvedType.fullyExpandedType(session)
if (unwrappedArgument is FirSmartCastExpression) {
val argumentType = argument.resolvedType.fullyExpandedType(session)
if (argument is FirSmartCastExpression) {
val substitutedParameterType = substitutor.substituteOrSelf(unsubstitutedParameterType)
// here we should use a substituted parameter type to properly choose the component of an intersection type
// to provide a proper cast to the smartcasted type
@@ -1058,7 +1055,7 @@ class CallAndReferenceGenerator(
}
// here we should pass unsubstituted parameter type to properly infer if the original type accepts null or not
// to properly insert nullability check
irArgument = irArgument.insertSpecialCast(unwrappedArgument, argumentType, unsubstitutedParameterType)
irArgument = irArgument.insertSpecialCast(argument, argumentType, unsubstitutedParameterType)
}
}
with(adapterGenerator) {
@@ -1067,12 +1064,12 @@ class CallAndReferenceGenerator(
val parameterType = parameter.returnTypeRef.coneType
val unwrappedParameterType = if (parameter.isVararg) parameterType.arrayElementType()!! else parameterType
val samFunctionType = getFunctionTypeForPossibleSamType(unwrappedParameterType)
irArgument = irArgument.applySuspendConversionIfNeeded(unwrappedArgument, samFunctionType ?: unwrappedParameterType)
irArgument = irArgument.applySamConversionIfNeeded(unwrappedArgument, parameter)
irArgument = irArgument.applySuspendConversionIfNeeded(argument, samFunctionType ?: unwrappedParameterType)
irArgument = irArgument.applySamConversionIfNeeded(argument, parameter)
}
}
return irArgument
.applyImplicitIntegerCoercionIfNeeded(unwrappedArgument, parameter)
.applyImplicitIntegerCoercionIfNeeded(argument, parameter)
}
private fun IrExpression.applyImplicitIntegerCoercionIfNeeded(