diff --git a/vlib/v/checker/fn.v b/vlib/v/checker/fn.v index a4e84873c7..898afc1bd9 100644 --- a/vlib/v/checker/fn.v +++ b/vlib/v/checker/fn.v @@ -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()) } diff --git a/vlib/v/tests/spawn_array_mut_test.v b/vlib/v/tests/spawn_array_mut_test.v new file mode 100644 index 0000000000..efc66a623e --- /dev/null +++ b/vlib/v/tests/spawn_array_mut_test.v @@ -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() +}