Skip to content

Commit

Permalink
cgen: fix assign the spawn or go expr to the []thread(fix #19365) (#1…
Browse files Browse the repository at this point in the history
  • Loading branch information
shove70 authored Sep 16, 2023
1 parent 0b0499b commit 255e724
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
6 changes: 6 additions & 0 deletions vlib/v/gen/c/cgen.v
Original file line number Diff line number Diff line change
Expand Up @@ -3269,16 +3269,22 @@ fn (mut g Gen) expr(node_ ast.Expr) {
}
}
ast.SpawnExpr {
old_is_arraymap_set := g.is_arraymap_set
g.is_arraymap_set = false
g.spawn_and_go_expr(node, .spawn_)
g.is_arraymap_set = old_is_arraymap_set
}
ast.GoExpr {
// XTODO this results in a cgen bug, order of fields is broken
// g.spawn_and_go_expr(ast.SpawnExpr{node.pos, node.call_expr, node.is_expr},
old_is_arraymap_set := g.is_arraymap_set
g.is_arraymap_set = false
g.spawn_and_go_expr(ast.SpawnExpr{
pos: node.pos
call_expr: node.call_expr
is_expr: node.is_expr
}, .go_)
g.is_arraymap_set = old_is_arraymap_set
}
ast.Ident {
g.ident(node)
Expand Down
11 changes: 11 additions & 0 deletions vlib/v/tests/thread_array_test.v
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
fn test_assign_spawn_to_element() {
mut threads := []thread{len: 1}

threads[0] = spawn fn () {
a := 1
dump(a)
assert true
}()

threads.wait()
}

0 comments on commit 255e724

Please sign in to comment.