diff --git a/vlib/v/gen/c/array.v b/vlib/v/gen/c/array.v index c48e7f0d51..04d2652a0b 100644 --- a/vlib/v/gen/c/array.v +++ b/vlib/v/gen/c/array.v @@ -345,10 +345,15 @@ fn (mut g Gen) gen_array_map(node ast.CallExpr) { } left_type := if node.left_type.has_flag(.shared_f) { node.left_type.clear_flag(.shared_f).deref() + } else if node.left_type.is_ptr() { + node.left_type.deref() } else { node.left_type } g.write('${g.typ(left_type)} ${tmp}_orig = ') + if !node.left_type.has_flag(.shared_f) && node.left_type.is_ptr() { + g.write('*') + } g.expr(node.left) if node.left_type.has_flag(.shared_f) { g.write('->val') diff --git a/vlib/v/gen/c/testdata/mutable_receiver_type_mapping.out b/vlib/v/gen/c/testdata/mutable_receiver_type_mapping.out new file mode 100644 index 0000000000..94133394da --- /dev/null +++ b/vlib/v/gen/c/testdata/mutable_receiver_type_mapping.out @@ -0,0 +1,3 @@ +[1, 0, 0] +[0, 1, 0] +[0, 0, 1] \ No newline at end of file diff --git a/vlib/v/gen/c/testdata/mutable_receiver_type_mapping.vv b/vlib/v/gen/c/testdata/mutable_receiver_type_mapping.vv new file mode 100644 index 0000000000..6c888beadd --- /dev/null +++ b/vlib/v/gen/c/testdata/mutable_receiver_type_mapping.vv @@ -0,0 +1,18 @@ +fn (mut a [][]f32) str() string { + return a.map(it.str()).join('\n') +} + +fn identity(n int) [][]f32 { + mut res := [][]f32{len: n, init: []f32{len: n, init: 0.0}} + for i in 0 .. n { + res[i][i] = 1.0 + } + + return res +} + +fn main() { + a := identity(3) + + println(a) +}