From 43173a5eeaeaca2d02465eee3f008aa1c267978b Mon Sep 17 00:00:00 2001 From: shove Date: Sat, 16 Sep 2023 19:49:10 +0800 Subject: [PATCH] cgen: fix assign the spawn or go expr to the []thread(fix #19365) (#19366) --- vlib/v/gen/c/cgen.v | 6 ++++++ vlib/v/tests/thread_array_test.v | 11 +++++++++++ 2 files changed, 17 insertions(+) create mode 100644 vlib/v/tests/thread_array_test.v diff --git a/vlib/v/gen/c/cgen.v b/vlib/v/gen/c/cgen.v index ff9c37e9dc9436..df8308a5230728 100644 --- a/vlib/v/gen/c/cgen.v +++ b/vlib/v/gen/c/cgen.v @@ -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) diff --git a/vlib/v/tests/thread_array_test.v b/vlib/v/tests/thread_array_test.v new file mode 100644 index 00000000000000..55f1eaabc7c76d --- /dev/null +++ b/vlib/v/tests/thread_array_test.v @@ -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() +}