cgen: fix cross assign in closure (#14549)
parent
7dcc19df55
commit
c0ef6dbde8
|
@ -625,12 +625,13 @@ fn (mut g Gen) gen_cross_var_assign(node &ast.AssignStmt) {
|
|||
ast.Ident {
|
||||
left_typ := node.left_types[i]
|
||||
left_sym := g.table.sym(left_typ)
|
||||
anon_ctx := if g.anon_fn { '$closure_ctx->' } else { '' }
|
||||
if left_sym.kind == .function {
|
||||
g.write_fn_ptr_decl(left_sym.info as ast.FnType, '_var_$left.pos.pos')
|
||||
g.writeln(' = ${c_name(left.name)};')
|
||||
g.writeln(' = $anon_ctx${c_name(left.name)};')
|
||||
} else {
|
||||
styp := g.typ(left_typ)
|
||||
g.writeln('$styp _var_$left.pos.pos = ${c_name(left.name)};')
|
||||
g.writeln('$styp _var_$left.pos.pos = $anon_ctx${c_name(left.name)};')
|
||||
}
|
||||
}
|
||||
ast.IndexExpr {
|
||||
|
|
|
@ -10,8 +10,7 @@ fn sma(period int) fn (f64) f64 {
|
|||
}
|
||||
|
||||
sum += input - storage[i]
|
||||
storage[i] = input
|
||||
i = (i + 1) % period
|
||||
storage[i], i = input, (i + 1) % period
|
||||
return sum / f64(storage.len)
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue