mirror of
https://github.com/Ed94/Odin.git
synced 2026-08-06 15:48:51 +00:00
Merge pull request #3363 from laytan/fix-c-varargs-named-args
fix named arguments and untyped nil with #c_vararg
This commit is contained in:
@@ -3359,6 +3359,9 @@ gb_internal lbValue lb_build_call_expr_internal(lbProcedure *p, Ast *expr) {
|
|||||||
for (Ast *var_arg : variadic) {
|
for (Ast *var_arg : variadic) {
|
||||||
lbValue arg = lb_build_expr(p, var_arg);
|
lbValue arg = lb_build_expr(p, var_arg);
|
||||||
if (is_type_any(elem_type)) {
|
if (is_type_any(elem_type)) {
|
||||||
|
if (is_type_untyped_nil(arg.type)) {
|
||||||
|
arg = lb_const_nil(p->module, t_rawptr);
|
||||||
|
}
|
||||||
array_add(&args, lb_emit_conv(p, arg, c_vararg_promote_type(default_type(arg.type))));
|
array_add(&args, lb_emit_conv(p, arg, c_vararg_promote_type(default_type(arg.type))));
|
||||||
} else {
|
} else {
|
||||||
array_add(&args, lb_emit_conv(p, arg, c_vararg_promote_type(elem_type)));
|
array_add(&args, lb_emit_conv(p, arg, c_vararg_promote_type(elem_type)));
|
||||||
@@ -3423,6 +3426,30 @@ gb_internal lbValue lb_build_call_expr_internal(lbProcedure *p, Ast *expr) {
|
|||||||
if (e->kind == Entity_TypeName) {
|
if (e->kind == Entity_TypeName) {
|
||||||
lbValue value = lb_const_nil(p->module, e->type);
|
lbValue value = lb_const_nil(p->module, e->type);
|
||||||
args[param_index] = value;
|
args[param_index] = value;
|
||||||
|
} else if (is_c_vararg && pt->variadic && pt->variadic_index == param_index) {
|
||||||
|
GB_ASSERT(param_index == pt->param_count-1);
|
||||||
|
Type *slice_type = e->type;
|
||||||
|
GB_ASSERT(slice_type->kind == Type_Slice);
|
||||||
|
Type *elem_type = slice_type->Slice.elem;
|
||||||
|
|
||||||
|
if (fv->value->kind == Ast_CompoundLit) {
|
||||||
|
ast_node(literal, CompoundLit, fv->value);
|
||||||
|
for (Ast *var_arg : literal->elems) {
|
||||||
|
lbValue arg = lb_build_expr(p, var_arg);
|
||||||
|
if (is_type_any(elem_type)) {
|
||||||
|
if (is_type_untyped_nil(arg.type)) {
|
||||||
|
arg = lb_const_nil(p->module, t_rawptr);
|
||||||
|
}
|
||||||
|
array_add(&args, lb_emit_conv(p, arg, c_vararg_promote_type(default_type(arg.type))));
|
||||||
|
} else {
|
||||||
|
array_add(&args, lb_emit_conv(p, arg, c_vararg_promote_type(elem_type)));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
lbValue value = lb_build_expr(p, fv->value);
|
||||||
|
GB_ASSERT(!is_type_tuple(value.type));
|
||||||
|
array_add(&args, lb_emit_conv(p, value, c_vararg_promote_type(value.type)));
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
lbValue value = lb_build_expr(p, fv->value);
|
lbValue value = lb_build_expr(p, fv->value);
|
||||||
GB_ASSERT(!is_type_tuple(value.type));
|
GB_ASSERT(!is_type_tuple(value.type));
|
||||||
|
|||||||
Reference in New Issue
Block a user