FIR2IR: minor refactoring of AdapterGenerator

This commit is contained in:
Mikhail Glukhikh
2022-06-30 14:45:41 +02:00
committed by Space
parent 1c4db63b47
commit c36e160f24
@@ -87,7 +87,7 @@ internal class AdapterGenerator(
function: IrFunction function: IrFunction
): Boolean = ): Boolean =
needSuspendConversion(type, function) || needCoercionToUnit(type, function) || needSuspendConversion(type, function) || needCoercionToUnit(type, function) ||
needVarargSpread(callableReferenceAccess) hasVarargOrDefaultArguments(callableReferenceAccess)
/** /**
* For example, * For example,
@@ -125,11 +125,12 @@ internal class AdapterGenerator(
* *
* At the use site, instead of referenced, we can put the adapter: { a, b -> referenced(a, b) } * At the use site, instead of referenced, we can put the adapter: { a, b -> referenced(a, b) }
*/ */
private fun needVarargSpread(callableReferenceAccess: FirCallableReferenceAccess): Boolean { private fun hasVarargOrDefaultArguments(callableReferenceAccess: FirCallableReferenceAccess): Boolean {
// Unbound callable reference 'A::foo' // Unbound callable reference 'A::foo'
return (callableReferenceAccess.calleeReference as? FirResolvedCallableReference)?.mappedArguments?.any { val calleeReference = callableReferenceAccess.calleeReference as? FirResolvedCallableReference ?: return false
it.value is ResolvedCallArgument.VarargArgument || it.value is ResolvedCallArgument.DefaultArgument return calleeReference.mappedArguments.any { (_, value) ->
} == true value is ResolvedCallArgument.VarargArgument || value is ResolvedCallArgument.DefaultArgument
}
} }
internal fun ConeKotlinType.kFunctionTypeToFunctionType(): IrSimpleType = internal fun ConeKotlinType.kFunctionTypeToFunctionType(): IrSimpleType =
@@ -318,10 +319,8 @@ internal class AdapterGenerator(
val receiverValue = IrGetValueImpl( val receiverValue = IrGetValueImpl(
startOffset, endOffset, adapterFunction.extensionReceiverParameter!!.symbol, IrStatementOrigin.ADAPTED_FUNCTION_REFERENCE startOffset, endOffset, adapterFunction.extensionReceiverParameter!!.symbol, IrStatementOrigin.ADAPTED_FUNCTION_REFERENCE
) )
when { if (boundDispatchReceiver != null) irCall.dispatchReceiver = receiverValue
boundDispatchReceiver != null -> irCall.dispatchReceiver = receiverValue else irCall.extensionReceiver = receiverValue
boundExtensionReceiver != null -> irCall.extensionReceiver = receiverValue
}
} else if (callableReferenceAccess.explicitReceiver is FirResolvedQualifier && ((firAdaptee as? FirMemberDeclaration)?.isStatic != true)) { } else if (callableReferenceAccess.explicitReceiver is FirResolvedQualifier && ((firAdaptee as? FirMemberDeclaration)?.isStatic != true)) {
// Unbound callable reference 'A::foo' // Unbound callable reference 'A::foo'
val adaptedReceiverParameter = adapterFunction.valueParameters[0] val adaptedReceiverParameter = adapterFunction.valueParameters[0]