From 60fbdc402fb959b1310e5392c3ae9b91e03ae00c Mon Sep 17 00:00:00 2001 From: Felipe Pena Date: Sun, 15 Dec 2024 17:32:29 -0300 Subject: [PATCH] fix --- vlib/v/gen/c/fn.v | 2 +- .../selector_call_with_reserved_c_name_test.v | 21 +++++++++++++++++++ 2 files changed, 22 insertions(+), 1 deletion(-) create mode 100644 vlib/v/tests/selector_call_with_reserved_c_name_test.v diff --git a/vlib/v/gen/c/fn.v b/vlib/v/gen/c/fn.v index 1d5fc20ae9ceb3..37a9a014a18f34 100644 --- a/vlib/v/gen/c/fn.v +++ b/vlib/v/gen/c/fn.v @@ -2180,7 +2180,7 @@ fn (mut g Gen) fn_call(node ast.CallExpr) { // Skip "C." name = util.no_dots(name[2..]) } else { - name = c_fn_name(name) + name = if is_selector_call { c_name(name) } else { c_fn_name(name) } } if g.pref.translated || g.file.is_translated || node.is_file_translated { // For `@[c: 'P_TryMove'] fn p_trymove( ... ` diff --git a/vlib/v/tests/selector_call_with_reserved_c_name_test.v b/vlib/v/tests/selector_call_with_reserved_c_name_test.v new file mode 100644 index 00000000000000..5dc13ae9610944 --- /dev/null +++ b/vlib/v/tests/selector_call_with_reserved_c_name_test.v @@ -0,0 +1,21 @@ +struct Foo { +} + +struct Bar { + do fn () bool = unsafe { nil } +} + +fn (f Foo) get() Bar { + return Bar{ + do: foobar + } +} + +fn foobar() bool { + return true +} + +fn test_main() { + t := Foo{} + assert t.get().do() == true +}