From 6a728e1674ab927ded26294f0065a3db7899713f Mon Sep 17 00:00:00 2001 From: yuyi Date: Mon, 8 Aug 2022 18:11:38 +0800 Subject: [PATCH] cgen: fix shared array.last() (#15379) --- vlib/v/gen/c/fn.v | 2 +- vlib/v/tests/shared_array_last_test.v | 13 +++++++++++++ 2 files changed, 14 insertions(+), 1 deletion(-) create mode 100644 vlib/v/tests/shared_array_last_test.v diff --git a/vlib/v/gen/c/fn.v b/vlib/v/gen/c/fn.v index 81cc4f364d..2d019937eb 100644 --- a/vlib/v/gen/c/fn.v +++ b/vlib/v/gen/c/fn.v @@ -1009,7 +1009,7 @@ fn (mut g Gen) method_call(node ast.CallExpr) { if !node.left.is_lvalue() { g.write('ADDR($rec_cc_type, ') has_cast = true - } else { + } else if node.name !in ['first', 'last', 'repeat'] { g.write('&') } } diff --git a/vlib/v/tests/shared_array_last_test.v b/vlib/v/tests/shared_array_last_test.v new file mode 100644 index 0000000000..97f359644c --- /dev/null +++ b/vlib/v/tests/shared_array_last_test.v @@ -0,0 +1,13 @@ +module main + +fn test_shared_array_last() { + shared a := []int{} + lock { + a << 1 + a << 2 + } + rlock a { + println(a.last()) + assert a.last() == 2 + } +}