From 00a0c1886eaa465904f07deebe06bdf01b408441 Mon Sep 17 00:00:00 2001 From: yuyi Date: Tue, 4 Jan 2022 16:36:29 +0800 Subject: [PATCH] ast, cgen: fix const fixed array of reference value (#13022) --- vlib/v/ast/table.v | 2 +- vlib/v/gen/c/cgen.v | 3 +++ .../tests/const_fixed_array_of_reference_value_test.v | 10 ++++++++++ 3 files changed, 14 insertions(+), 1 deletion(-) create mode 100644 vlib/v/tests/const_fixed_array_of_reference_value_test.v diff --git a/vlib/v/ast/table.v b/vlib/v/ast/table.v index 48253b8bb5..d899a4801c 100644 --- a/vlib/v/ast/table.v +++ b/vlib/v/ast/table.v @@ -835,7 +835,7 @@ pub fn (t &Table) array_fixed_cname(elem_type Type, size int) string { if elem_type.is_ptr() { res = '_ptr$elem_type.nr_muls()' } - return 'Array_fixed_${elem_type_sym.cname}_$size' + res + return 'Array_fixed_$elem_type_sym.cname${res}_$size' } [inline] diff --git a/vlib/v/gen/c/cgen.v b/vlib/v/gen/c/cgen.v index 1413f05dba..7e4b5dce57 100644 --- a/vlib/v/gen/c/cgen.v +++ b/vlib/v/gen/c/cgen.v @@ -1138,6 +1138,9 @@ pub fn (mut g Gen) write_typedef_types() { if fixed.starts_with('C__') { fixed = fixed[3..] } + if fixed.contains('ptr') { + fixed = 'void*' + } if elem_sym.info is ast.FnType { pos := g.out.len g.write_fn_ptr_decl(&elem_sym.info, '') diff --git a/vlib/v/tests/const_fixed_array_of_reference_value_test.v b/vlib/v/tests/const_fixed_array_of_reference_value_test.v new file mode 100644 index 0000000000..4054801de0 --- /dev/null +++ b/vlib/v/tests/const_fixed_array_of_reference_value_test.v @@ -0,0 +1,10 @@ +const ( + foo = u32(1) + bar = u32(2) + weapon_keys = [&foo, &bar]! +) + +fn test_const_fixed_array_of_ref_value() { + assert weapon_keys[0] == &foo + assert weapon_keys[1] == &bar +}