if (method.getReturnType() == PrimitiveTypes.Void) {
throw Error.operatorMethodMustNotReturnVoid(method);
}
final ParameterList parameters = method.getParameters();
assert parameters.size() == conversion.getParameters().size();
if (parameters.size() != 1) {
throw Error.incorrectNumberOfMethodCallArguments(method);
}
//
// The return type must match exactly.
//
if (!TypeUtils.areEquivalent(method.getReturnType(), right.getType())) {
throw Error.operandTypesDoNotMatchParameters(ExpressionType.Coalesce, method);
}
//
// The parameter of the conversion lambda must either be assignable from the erased
// or un-erased type of the left hand side.
//
if (!parameterIsAssignable(parameters.get(0).getParameterType(), TypeUtils.getUnderlyingPrimitiveOrSelf(left.getType())) &&
!parameterIsAssignable(parameters.get(0).getParameterType(), left.getType())) {
throw Error.operandTypesDoNotMatchParameters(ExpressionType.Coalesce, method);
}
return new CoalesceConversionBinaryExpression(left, right, conversion);