From 2d8f160ef13dd0912f319fcc07106ba3cbc2099b Mon Sep 17 00:00:00 2001 From: walking devel <104449470+walkingdevel@users.noreply.github.com> Date: Fri, 13 Jan 2023 11:23:51 +0000 Subject: [PATCH] checker: replace the `go` keyword in error messages with `spawn` (#16960) --- vlib/v/checker/fn.v | 6 +++--- vlib/v/checker/tests/go_expr.out | 6 +++--- vlib/v/checker/tests/go_expr.vv | 2 +- vlib/v/checker/tests/go_mut_arg.out | 6 +++--- vlib/v/checker/tests/go_mut_arg.vv | 2 +- vlib/v/checker/tests/go_mut_receiver.out | 6 +++--- vlib/v/checker/tests/go_mut_receiver.vv | 2 +- vlib/v/checker/tests/go_wait_or.out | 20 ++++++++++---------- vlib/v/checker/tests/go_wait_or.vv | 18 +++++++++--------- vlib/v/parser/fn.v | 2 +- 10 files changed, 35 insertions(+), 35 deletions(-) diff --git a/vlib/v/checker/fn.v b/vlib/v/checker/fn.v index 8b19582783..d3a287651b 100644 --- a/vlib/v/checker/fn.v +++ b/vlib/v/checker/fn.v @@ -1958,19 +1958,19 @@ fn (mut c Checker) method_call(mut node ast.CallExpr) ast.Type { fn (mut c Checker) go_expr(mut node ast.GoExpr) ast.Type { ret_type := c.call_expr(mut node.call_expr) if node.call_expr.or_block.kind != .absent { - c.error('option handling cannot be done in `go` call. Do it when calling `.wait()`', + c.error('option handling cannot be done in `spawn` call. Do it when calling `.wait()`', node.call_expr.or_block.pos) } // Make sure there are no mutable arguments for arg in node.call_expr.args { if arg.is_mut && !arg.typ.is_ptr() { - c.error('function in `go` statement cannot contain mutable non-reference arguments', + c.error('function in `spawn` statement cannot contain mutable non-reference arguments', arg.expr.pos()) } } if node.call_expr.is_method && node.call_expr.receiver_type.is_ptr() && !node.call_expr.left_type.is_ptr() { - c.error('method in `go` statement cannot have non-reference mutable receiver', + c.error('method in `spawn` statement cannot have non-reference mutable receiver', node.call_expr.left.pos()) } diff --git a/vlib/v/checker/tests/go_expr.out b/vlib/v/checker/tests/go_expr.out index e19c961574..4c06cce383 100644 --- a/vlib/v/checker/tests/go_expr.out +++ b/vlib/v/checker/tests/go_expr.out @@ -1,5 +1,5 @@ -vlib/v/checker/tests/go_expr.vv:2:5: error: expression in `go` must be a function call +vlib/v/checker/tests/go_expr.vv:2:8: error: expression in `spawn` must be a function call 1 | fn main() { - 2 | go 1 - | ^ + 2 | spawn 1 + | ^ 3 | } diff --git a/vlib/v/checker/tests/go_expr.vv b/vlib/v/checker/tests/go_expr.vv index 969b29dc5e..99c992f411 100644 --- a/vlib/v/checker/tests/go_expr.vv +++ b/vlib/v/checker/tests/go_expr.vv @@ -1,3 +1,3 @@ fn main() { - go 1 + spawn 1 } diff --git a/vlib/v/checker/tests/go_mut_arg.out b/vlib/v/checker/tests/go_mut_arg.out index 70271b1fb9..1b31d7e3c7 100644 --- a/vlib/v/checker/tests/go_mut_arg.out +++ b/vlib/v/checker/tests/go_mut_arg.out @@ -1,6 +1,6 @@ -vlib/v/checker/tests/go_mut_arg.vv:14:16: error: function in `go` statement cannot contain mutable non-reference arguments +vlib/v/checker/tests/go_mut_arg.vv:14:19: error: function in `spawn` statement cannot contain mutable non-reference arguments 12 | a: 0 13 | } - 14 | go change(mut x) - | ^ + 14 | spawn change(mut x) + | ^ 15 | } diff --git a/vlib/v/checker/tests/go_mut_arg.vv b/vlib/v/checker/tests/go_mut_arg.vv index af86f15d1c..cd05b1edd3 100644 --- a/vlib/v/checker/tests/go_mut_arg.vv +++ b/vlib/v/checker/tests/go_mut_arg.vv @@ -11,5 +11,5 @@ fn main() { mut x := St{ a: 0 } - go change(mut x) + spawn change(mut x) } diff --git a/vlib/v/checker/tests/go_mut_receiver.out b/vlib/v/checker/tests/go_mut_receiver.out index f8b2681b48..2a7af53487 100644 --- a/vlib/v/checker/tests/go_mut_receiver.out +++ b/vlib/v/checker/tests/go_mut_receiver.out @@ -1,6 +1,6 @@ -vlib/v/checker/tests/go_mut_receiver.vv:14:5: error: method in `go` statement cannot have non-reference mutable receiver +vlib/v/checker/tests/go_mut_receiver.vv:14:8: error: method in `spawn` statement cannot have non-reference mutable receiver 12 | a: 0 13 | } - 14 | go x.change() - | ^ + 14 | spawn x.change() + | ^ 15 | } diff --git a/vlib/v/checker/tests/go_mut_receiver.vv b/vlib/v/checker/tests/go_mut_receiver.vv index 0b64d51c23..dc5b1b86d8 100644 --- a/vlib/v/checker/tests/go_mut_receiver.vv +++ b/vlib/v/checker/tests/go_mut_receiver.vv @@ -11,5 +11,5 @@ fn main() { mut x := St{ a: 0 } - go x.change() + spawn x.change() } diff --git a/vlib/v/checker/tests/go_wait_or.out b/vlib/v/checker/tests/go_wait_or.out index 0389ca6d6e..11a9b5d181 100644 --- a/vlib/v/checker/tests/go_wait_or.out +++ b/vlib/v/checker/tests/go_wait_or.out @@ -1,5 +1,5 @@ vlib/v/checker/tests/go_wait_or.vv:11:16: error: unexpected `?`, the function `wait` does not return an option or a result - 9 | go d(1) + 9 | spawn d(1) 10 | ] 11 | r := tg.wait()? | ^ @@ -13,7 +13,7 @@ vlib/v/checker/tests/go_wait_or.vv:13:20: error: unexpected `or` block, the func 14 | println(s) 15 | tg2 := [ vlib/v/checker/tests/go_wait_or.vv:19:13: error: unexpected `or` block, the function `wait` does not return an option or a result - 17 | go e(1) + 17 | spawn e(1) 18 | ] 19 | tg2.wait() or { panic('problem') } | ~~~~~~~~~~~~~~~~~~~~~~~ @@ -25,9 +25,9 @@ vlib/v/checker/tests/go_wait_or.vv:20:15: error: unexpected `?`, the function `w 20 | tg2[0].wait()? | ^ 21 | tg3 := [ - 22 | go f(0) + 22 | spawn f(0) vlib/v/checker/tests/go_wait_or.vv:25:6: error: `.wait()` cannot be called for an array when thread functions return options. Iterate over the arrays elements instead and handle each returned option with `or`. - 23 | go f(1) + 23 | spawn f(1) 24 | ] 25 | tg3.wait() or { panic('problem') } | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ @@ -48,22 +48,22 @@ vlib/v/checker/tests/go_wait_or.vv:31:15: error: wait() returns an option, so it 32 | println(a) 33 | } vlib/v/checker/tests/go_wait_or.vv:38:6: error: `.wait()` cannot be called for an array when thread functions return options. Iterate over the arrays elements instead and handle each returned option with `or`. - 36 | go g(1) + 36 | spawn g(1) 37 | ] 38 | tg4.wait() | ~~~~~~ 39 | tg4[0].wait() - 40 | go g(3) or { panic('problem') } + 40 | spawn g(3) or { panic('problem') } vlib/v/checker/tests/go_wait_or.vv:39:9: error: wait() returns an option, so it should have either an `or {}` block, or `?` at the end 37 | ] 38 | tg4.wait() 39 | tg4[0].wait() | ~~~~~~ - 40 | go g(3) or { panic('problem') } + 40 | spawn g(3) or { panic('problem') } 41 | } -vlib/v/checker/tests/go_wait_or.vv:40:10: error: option handling cannot be done in `go` call. Do it when calling `.wait()` +vlib/v/checker/tests/go_wait_or.vv:40:13: error: option handling cannot be done in `spawn` call. Do it when calling `.wait()` 38 | tg4.wait() 39 | tg4[0].wait() - 40 | go g(3) or { panic('problem') } - | ~~~~~~~~~~~~~~~~~~~~~~~ + 40 | spawn g(3) or { panic('problem') } + | ~~~~~~~~~~~~~~~~~~~~~~~ 41 | } \ No newline at end of file diff --git a/vlib/v/checker/tests/go_wait_or.vv b/vlib/v/checker/tests/go_wait_or.vv index 7c5aab9a15..2866b1b6a9 100644 --- a/vlib/v/checker/tests/go_wait_or.vv +++ b/vlib/v/checker/tests/go_wait_or.vv @@ -5,22 +5,22 @@ fn g(n int) ? { } fn main() { tg := [ - go d(0) - go d(1) + spawn d(0) + spawn d(1) ] r := tg.wait()? println(r) s := tg[0].wait() or { panic('problem') } println(s) tg2 := [ - go e(0) - go e(1) + spawn e(0) + spawn e(1) ] tg2.wait() or { panic('problem') } tg2[0].wait()? tg3 := [ - go f(0) - go f(1) + spawn f(0) + spawn f(1) ] tg3.wait() or { panic('problem') } for t in tg3 { @@ -32,10 +32,10 @@ fn main() { println(a) } tg4 := [ - go g(0) - go g(1) + spawn g(0) + spawn g(1) ] tg4.wait() tg4[0].wait() - go g(3) or { panic('problem') } + spawn g(3) or { panic('problem') } } diff --git a/vlib/v/parser/fn.v b/vlib/v/parser/fn.v index 3c9c599f5b..ead322928f 100644 --- a/vlib/v/parser/fn.v +++ b/vlib/v/parser/fn.v @@ -1014,7 +1014,7 @@ fn (mut p Parser) go_expr() ast.GoExpr { call_expr := if expr is ast.CallExpr { expr } else { - p.error_with_pos('expression in `go` must be a function call', expr.pos()) + p.error_with_pos('expression in `spawn` must be a function call', expr.pos()) ast.CallExpr{ scope: p.scope }