From 07d74065353581039e31b016fb00992e8e08162c Mon Sep 17 00:00:00 2001 From: Felipe Pena Date: Sat, 21 Dec 2024 20:15:57 -0300 Subject: [PATCH] fix --- vlib/v/checker/fn.v | 2 +- .../gen/c/testdata/literal_c_variadic_arg.out | 1 + .../gen/c/testdata/literal_c_variadic_arg.vv | 22 +++++++++++++++++++ 3 files changed, 24 insertions(+), 1 deletion(-) create mode 100644 vlib/v/gen/c/testdata/literal_c_variadic_arg.out create mode 100644 vlib/v/gen/c/testdata/literal_c_variadic_arg.vv diff --git a/vlib/v/checker/fn.v b/vlib/v/checker/fn.v index 12d9aa2c182eb5..af7f3ef8f3c93b 100644 --- a/vlib/v/checker/fn.v +++ b/vlib/v/checker/fn.v @@ -1593,7 +1593,7 @@ fn (mut c Checker) fn_call(mut node ast.CallExpr, mut continue_check &bool) ast. || param.typ == ast.nil_type || final_param_sym.idx == ast.nil_type_idx) && !call_arg.typ.is_any_kind_of_pointer() && func.language == .v && !call_arg.expr.is_lvalue() && !c.pref.translated && !c.file.is_translated - && func.name !in ['json.encode', 'json.encode_pretty'] { + && !func.is_c_variadic && func.name !in ['json.encode', 'json.encode_pretty'] { c.error('expression cannot be passed as `voidptr`', call_arg.expr.pos()) } // Handle expected interface diff --git a/vlib/v/gen/c/testdata/literal_c_variadic_arg.out b/vlib/v/gen/c/testdata/literal_c_variadic_arg.out new file mode 100644 index 00000000000000..2323ea1a2abf84 --- /dev/null +++ b/vlib/v/gen/c/testdata/literal_c_variadic_arg.out @@ -0,0 +1 @@ +foo : 1 : 2.50, 42, v diff --git a/vlib/v/gen/c/testdata/literal_c_variadic_arg.vv b/vlib/v/gen/c/testdata/literal_c_variadic_arg.vv new file mode 100644 index 00000000000000..670e4dd44a6f19 --- /dev/null +++ b/vlib/v/gen/c/testdata/literal_c_variadic_arg.vv @@ -0,0 +1,22 @@ +#include + +@[typedef] +struct C.va_list {} + +fn C.va_start(voidptr, voidptr) +fn C.va_end(voidptr) + +fn C.vfprintf(&C.FILE, &char, C.va_list) int + +fn t2(fmt voidptr, ...) { + ap := C.va_list{} + C.va_start(ap, fmt) + C.vfprintf(C.stderr, fmt, ap) + C.va_end(ap) +} + +fn main() { + a := 1 + b := 2.5 + t2(c'%s : %d : %.2f, %d, %c\n', c'foo', a, b, 42, `v`) +}