Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cgen: fix assign the spawn or go expr to the []thread(fix #19365) #19366

Merged
merged 1 commit into from
Sep 16, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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()
}
Loading