cgen: fix a bug (deleting a map key while iterating on the same map) detected by `-d debug_realloc`

pull/9325/head
Delyan Angelov 2021-03-16 09:20:45 +02:00
parent 93df560cf9
commit 506561c792
No known key found for this signature in database
GPG Key ID: 66886C0F12D595ED
1 changed files with 6 additions and 1 deletions

View File

@ -405,11 +405,16 @@ fn (mut g Gen) comp_for(node ast.CompFor) {
g.stmts(node.stmts) g.stmts(node.stmts)
i++ i++
g.writeln('}') g.writeln('}')
//
mut delete_keys := []string{}
for key, _ in g.comptime_var_type_map { for key, _ in g.comptime_var_type_map {
if key.starts_with(node.val_var) { if key.starts_with(node.val_var) {
g.comptime_var_type_map.delete(key) delete_keys << key
} }
} }
for key in delete_keys {
g.comptime_var_type_map.delete(key)
}
} }
} else if node.kind == .fields { } else if node.kind == .fields {
// TODO add fields // TODO add fields