Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
felipensp committed Sep 23, 2024
1 parent 4f39bac commit 2a58616
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
2 changes: 1 addition & 1 deletion vlib/v/gen/c/fn.v
Original file line number Diff line number Diff line change
Expand Up @@ -1675,7 +1675,7 @@ 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.receiver_type.is_ptr() && !left_type.is_ptr() {
if node.name == 'clone' && node.receiver_type.is_ptr() && !left_type.is_ptr() {
if node.left is ast.IndexExpr {
idx := node.left.index
if idx is ast.RangeExpr {
Expand Down
16 changes: 16 additions & 0 deletions vlib/v/tests/fns/method_call_on_rangeexpr_test.v
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
type Buffer = []byte

pub fn (mut sb Buffer) vbytes() string {
return sb[0..sb.len].a().str()
}

pub fn (mut sb Buffer) a() Buffer {
return sb
}

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

0 comments on commit 2a58616

Please sign in to comment.