mirror of
https://github.com/vlang/v.git
synced 2025-09-13 22:42:26 +03:00
checker: allow pass array as mut param to spawn fn (#21283)
This commit is contained in:
parent
0a14bef008
commit
be90cf3165
2 changed files with 18 additions and 0 deletions
|
@ -2516,6 +2516,10 @@ fn (mut c Checker) spawn_expr(mut node ast.SpawnExpr) ast.Type {
|
|||
// Make sure there are no mutable arguments
|
||||
for arg in node.call_expr.args {
|
||||
if arg.is_mut && !arg.typ.is_ptr() {
|
||||
if c.table.final_sym(arg.typ).kind == .array {
|
||||
// allow mutable []array to be passed as mut
|
||||
continue
|
||||
}
|
||||
c.error('function in `spawn` statement cannot contain mutable non-reference arguments',
|
||||
arg.expr.pos())
|
||||
}
|
||||
|
|
14
vlib/v/tests/spawn_array_mut_test.v
Normal file
14
vlib/v/tests/spawn_array_mut_test.v
Normal file
|
@ -0,0 +1,14 @@
|
|||
fn mutable_array_arg(mut a []int) {
|
||||
println(a)
|
||||
a << 4
|
||||
assert a.len == 4
|
||||
}
|
||||
|
||||
fn test_main() {
|
||||
mut a := []int{}
|
||||
a << 1
|
||||
a << 2
|
||||
a << 3
|
||||
w := spawn mutable_array_arg(mut a)
|
||||
w.wait()
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue