cgen: fix cross assign in closure (#14549)

master
yuyi 2022-05-29 01:47:54 +08:00 committed by GitHub
parent 7dcc19df55
commit c0ef6dbde8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 4 additions and 4 deletions

View File

@ -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 {

View File

@ -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)
}
}