File tree Expand file tree Collapse file tree 2 files changed +36
-2
lines changed Expand file tree Collapse file tree 2 files changed +36
-2
lines changed Original file line number Diff line number Diff line change @@ -487,12 +487,30 @@ fn (mut g Gen) gen_anon_fn(mut node ast.AnonFn) {
487
487
if obj is ast.Var {
488
488
if obj.has_inherited {
489
489
has_inherited = true
490
- g.writeln ('.${var.name} = ${c.closure_ctx} ->${var.name} ,' )
490
+ var_sym := g.table.sym (var.typ)
491
+ if var_sym.info is ast.ArrayFixed {
492
+ g.write ('.${var.name} = {' )
493
+ for i in 0 .. var_sym.info.size {
494
+ g.write ('${c.closure_ctx} ->${var.name} [${i} ],' )
495
+ }
496
+ g.writeln ('},' )
497
+ } else {
498
+ g.writeln ('.${var.name} = ${c.closure_ctx} ->${var.name} ,' )
499
+ }
491
500
}
492
501
}
493
502
}
494
503
if ! has_inherited {
495
- g.writeln ('.${var.name} = ${var.name} ,' )
504
+ var_sym := g.table.sym (var.typ)
505
+ if var_sym.info is ast.ArrayFixed {
506
+ g.write ('.${var.name} = {' )
507
+ for i in 0 .. var_sym.info.size {
508
+ g.write ('${var.name} [${i} ],' )
509
+ }
510
+ g.writeln ('},' )
511
+ } else {
512
+ g.writeln ('.${var.name} = ${var.name} ,' )
513
+ }
496
514
}
497
515
}
498
516
g.indent--
Original file line number Diff line number Diff line change
1
+ struct Crasher {
2
+ value int
3
+ }
4
+
5
+ fn crash (c [1 ]Crasher) fn () int {
6
+ return fn [c] () int {
7
+ println (c[0 ].value)
8
+ return c[0 ].value
9
+ }
10
+ }
11
+
12
+ fn test_closure_with_fixed_array_var () {
13
+ crash_fn := crash ([Crasher{1 }]! )
14
+ ret := crash_fn ()
15
+ assert ret == 1
16
+ }
You can’t perform that action at this time.
0 commit comments