diff --git a/vlib/v/gen/c/array.v b/vlib/v/gen/c/array.v index cdb3a16016f97c..857b73ec34c9b7 100644 --- a/vlib/v/gen/c/array.v +++ b/vlib/v/gen/c/array.v @@ -1146,10 +1146,13 @@ fn (mut g Gen) gen_array_index(node ast.CallExpr) { } g.expr(node.left) g.write(', ') - if node.args[0].expr.is_auto_deref_var() { + + elem_typ := g.table.sym(node.left_type).array_info().elem_type + // auto deref var is redundant for interfaces and sum types. + if node.args[0].expr.is_auto_deref_var() + && g.table.sym(elem_typ).kind !in [.interface_, .sum_type] { g.write('*') } - elem_typ := g.table.sym(node.left_type).array_info().elem_type if g.table.sym(elem_typ).kind in [.interface_, .sum_type] { g.expr_with_cast(node.args[0].expr, node.args[0].typ, elem_typ) } else { diff --git a/vlib/v/tests/interface_arr_for_mut_iter_index_test.v b/vlib/v/tests/interface_arr_for_mut_iter_index_test.v new file mode 100644 index 00000000000000..d8d6d913ce925f --- /dev/null +++ b/vlib/v/tests/interface_arr_for_mut_iter_index_test.v @@ -0,0 +1,14 @@ +interface Ennemi { +} + +struct Map { + ennemis []Ennemi +} + +fn test_interface_arr_for_mut_iter_index() { + mut maap := Map{} + + for mut ennemi in maap.ennemis { + assert maap.ennemis.index(ennemi) == 0 + } +}