Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
felipensp committed Sep 24, 2024
1 parent 2a58616 commit 53ce4ce
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 4 deletions.
11 changes: 9 additions & 2 deletions vlib/v/gen/c/fn.v
Original file line number Diff line number Diff line change
Expand Up @@ -1675,13 +1675,15 @@ fn (mut g Gen) method_call(node ast.CallExpr) {
// if so, then instead of calling array_clone(&array_slice(...))
// call array_clone_static(array_slice(...))
mut is_range_slice := false
if node.name == 'clone' && node.receiver_type.is_ptr() && !left_type.is_ptr() {
if node.receiver_type.is_ptr() && !left_type.is_ptr() {
if node.left is ast.IndexExpr {
idx := node.left.index
if idx is ast.RangeExpr {
// expr is arr[range].clone()
// use array_clone_static instead of array_clone
name = util.no_dots('${receiver_type_name}_${node.name}_static')
if node.name == 'clone' {
name = util.no_dots('${receiver_type_name}_${node.name}_static')
}
is_range_slice = true
}
}
Expand Down Expand Up @@ -1759,6 +1761,11 @@ fn (mut g Gen) method_call(node ast.CallExpr) {
&& g.typ(left_type) == g.typ(node.receiver_type)) {
g.write('&')
}
} else {
if node.name != 'clone' && !left_type.is_ptr() {
g.write('ADDR(${rec_cc_type}, ')
cast_n++
}
}
} else if !node.receiver_type.is_ptr() && left_type.is_ptr() && node.name != 'str'
&& node.from_embed_types.len == 0 {
Expand Down
4 changes: 2 additions & 2 deletions vlib/v/tests/fns/method_call_on_rangeexpr_test.v
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
type Buffer = []byte
type Buffer = []u8

pub fn (mut sb Buffer) vbytes() string {
return sb[0..sb.len].a().str()
Expand All @@ -9,7 +9,7 @@ pub fn (mut sb Buffer) a() Buffer {
}

fn test_main() {
mut b := Buffer([]byte{cap: 10})
mut b := Buffer([]u8{cap: 10})
b << 1
b << 2
assert b.vbytes() == 'Buffer([1, 2])'
Expand Down

0 comments on commit 53ce4ce

Please sign in to comment.