From 0de5e986c74e58b5efa94ddff692a1ef3a660215 Mon Sep 17 00:00:00 2001 From: yuyi Date: Wed, 25 Dec 2024 00:36:08 +0800 Subject: [PATCH] cgen: fix try_push string literal to channel (fix #23242) (#23259) --- vlib/v/gen/c/fn.v | 5 ++++- vlib/v/tests/concurrency/chan_try_push_literal_test.v | 5 +++++ 2 files changed, 9 insertions(+), 1 deletion(-) create mode 100644 vlib/v/tests/concurrency/chan_try_push_literal_test.v diff --git a/vlib/v/gen/c/fn.v b/vlib/v/gen/c/fn.v index e916a38d0..76f95a618 100644 --- a/vlib/v/gen/c/fn.v +++ b/vlib/v/gen/c/fn.v @@ -2924,7 +2924,10 @@ fn (mut g Gen) ref_or_deref_arg(arg ast.CallArg, expected_type ast.Type, lang as g.expr_with_opt(arg.expr, arg_typ, expected_type) return } else if arg.expr.is_literal() { - g.write('(voidptr)') + g.write('(voidptr)ADDR(${g.styp(arg_typ)}, ') + g.expr(arg.expr) + g.write(')') + return } else { if arg_typ_sym.kind in [.sum_type, .interface] { atype = arg_typ diff --git a/vlib/v/tests/concurrency/chan_try_push_literal_test.v b/vlib/v/tests/concurrency/chan_try_push_literal_test.v new file mode 100644 index 000000000..22017dce7 --- /dev/null +++ b/vlib/v/tests/concurrency/chan_try_push_literal_test.v @@ -0,0 +1,5 @@ +fn test_chan_try_push_literal() { + foo := chan string{} + foo.try_push('some string') + assert true +} -- 2.39.5