1
0
mirror of https://github.com/vlang/v.git synced 2023-08-10 21:13:21 +03:00

checker: replace the go keyword in error messages with spawn (#16960)

This commit is contained in:
walking devel 2023-01-13 11:23:51 +00:00 committed by GitHub
parent c766ce4fe5
commit 2d8f160ef1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
10 changed files with 35 additions and 35 deletions

View File

@ -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())
}

View File

@ -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 | }

View File

@ -1,3 +1,3 @@
fn main() {
go 1
spawn 1
}

View File

@ -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 | }

View File

@ -11,5 +11,5 @@ fn main() {
mut x := St{
a: 0
}
go change(mut x)
spawn change(mut x)
}

View File

@ -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 | }

View File

@ -11,5 +11,5 @@ fn main() {
mut x := St{
a: 0
}
go x.change()
spawn x.change()
}

View File

@ -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 | }

View File

@ -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') }
}

View File

@ -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
}