File tree Expand file tree Collapse file tree 2 files changed +49
-0
lines changed Expand file tree Collapse file tree 2 files changed +49
-0
lines changed Original file line number Diff line number Diff line change @@ -658,6 +658,30 @@ fn (mut g Gen) gen_cross_var_assign(node &ast.AssignStmt) {
658
658
g.write (', ' )
659
659
g.expr (left.index)
660
660
g.writeln (');' )
661
+ } else if sym.kind == .array_fixed {
662
+ info := sym.info as ast.ArrayFixed
663
+ elem_typ := g.table.sym (info.elem_type)
664
+ if elem_typ.kind == .function {
665
+ left_typ := node.left_types[i]
666
+ left_sym := g.table.sym (left_typ)
667
+ g.write_fn_ptr_decl (left_sym.info as ast.FnType , '_var_$left.pos.pos ' )
668
+ g.write (' = *(voidptr*)' )
669
+ } else {
670
+ styp := g.typ (info.elem_type)
671
+ g.write ('$styp _var_$left.pos.pos = ' )
672
+ }
673
+ if left.left_type.is_ptr () {
674
+ g.write ('*' )
675
+ }
676
+ needs_clone := info.elem_type == ast.string_type && g.is_autofree
677
+ if needs_clone {
678
+ g.write ('/*1*/string_clone(' )
679
+ }
680
+ g.expr (left)
681
+ if needs_clone {
682
+ g.write (')' )
683
+ }
684
+ g.writeln (';' )
661
685
} else if sym.kind == .map {
662
686
info := sym.info as ast.Map
663
687
skeytyp := g.typ (info.key_type)
Original file line number Diff line number Diff line change
1
+ fn test_cross_assign_fixed_array () {
2
+ number := 5
3
+ ans := fib (number)
4
+
5
+ println (ans)
6
+ assert ans == 21
7
+ }
8
+
9
+ fn fib (n int ) u64 {
10
+ if n < = 0 {
11
+ panic ('Bad number' )
12
+ }
13
+ return match n {
14
+ 1 | 2 {
15
+ 1
16
+ }
17
+ else {
18
+ mut pair := [1 , 2 ]!
19
+ for _ in 0 .. n {
20
+ pair[0 ], pair[1 ] = pair[1 ], pair[0 ] + pair[1 ]
21
+ }
22
+ pair[1 ]
23
+ }
24
+ }
25
+ }
You can’t perform that action at this time.
0 commit comments