File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -969,6 +969,11 @@ fn (mut g Gen) assign_stmt(node_ ast.AssignStmt) {
969969 defer {
970970 g.is_option_auto_heap = old_is_auto_heap
971971 }
972+ if val is ast.Ident && val.is_mut () && var_type.is_ptr () {
973+ if var_type.nr_muls () < val_type.nr_muls () {
974+ g.write ('*' .repeat (var_type.nr_muls ()))
975+ }
976+ }
972977 g.is_option_auto_heap = val_type.has_flag (.option) && val is ast.PrefixExpr
973978 && val.right is ast.Ident && (val.right as ast.Ident ).is_auto_heap ()
974979 if var_type.has_flag (.option) || gen_or {
Original file line number Diff line number Diff line change 1+ @[heap]
2+ struct Demo {
3+ a string
4+ }
5+
6+ fn test_main () {
7+ mut rl := [& Demo{'A' }]
8+
9+ assert rl[0 ].a == 'A'
10+
11+ mut p := & Demo{}
12+ for mut e in rl {
13+ p = e
14+ }
15+
16+ assert p.a == 'A'
17+
18+ for i in 0 .. rl.len {
19+ mut e := rl[i]
20+ p = e
21+ }
22+
23+ assert p.a == 'A'
24+ }
You can’t perform that action at this time.
0 commit comments