diff --git a/vlib/v/gen/c/for.v b/vlib/v/gen/c/for.v index 0e31f3e689..50a802ed6c 100644 --- a/vlib/v/gen/c/for.v +++ b/vlib/v/gen/c/for.v @@ -322,7 +322,7 @@ fn (mut g Gen) for_in_stmt(node_ ast.ForInStmt) { g.writeln('\t${styp} ${c_name(node.val_var)};') g.writeln('\tmemcpy(*(${styp}*)${c_name(node.val_var)}, (byte*)${cond_var}[${idx}], sizeof(${styp}));') } else { - mut styp := g.styp(node.val_type) + styp := g.styp(node.val_type) g.write('\t${styp} ${c_name(node.val_var)}') } if !is_fixed_array { diff --git a/vlib/v/gen/c/str.v b/vlib/v/gen/c/str.v index b7c736c606..6d3bab7f05 100644 --- a/vlib/v/gen/c/str.v +++ b/vlib/v/gen/c/str.v @@ -120,7 +120,7 @@ fn (mut g Gen) gen_expr_to_string(expr ast.Expr, etype ast.Type) { exp_typ := if unwrap_option { typ.clear_flag(.option) } else { typ } is_dump_expr := expr is ast.DumpExpr is_var_mut := expr.is_auto_deref_var() - mut str_fn_name := g.get_str_fn(exp_typ) + str_fn_name := g.get_str_fn(exp_typ) temp_var_needed := expr is ast.CallExpr && (expr.return_type.is_ptr() || g.table.sym(expr.return_type).is_c_struct()) mut tmp_var := '' @@ -171,7 +171,7 @@ fn (mut g Gen) gen_expr_to_string(expr ast.Expr, etype ast.Type) { } } else if is_ptr && typ.has_flag(.option) { if typ.has_flag(.option_mut_param_t) { - g.write('/**/*') + g.write('*') } else { g.write('*(${g.styp(typ)}*)&') } diff --git a/vlib/v/tests/options/option_for_mut_test.v b/vlib/v/tests/options/option_for_mut_test.v new file mode 100644 index 0000000000..37650f5f5a --- /dev/null +++ b/vlib/v/tests/options/option_for_mut_test.v @@ -0,0 +1,15 @@ +module main + +fn test_main() { + mut data := [3]?int{} + + for mut d in data { + d = ?int(1) + assert '${d}' == 'Option(1)' + } + + for i in 0 .. data.len { + data[i] = ?int(3) + } + assert '${data}' == '[Option(3), Option(3), Option(3)]' +}