Skip to content

Commit 6e8124f

Browse files
authored
checker: fix spawn when calling undefined function (#21906)
1 parent 22df56f commit 6e8124f

File tree

3 files changed

+50
-0
lines changed

3 files changed

+50
-0
lines changed

vlib/v/checker/fn.v

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2584,6 +2584,10 @@ fn (mut c Checker) spawn_expr(mut node ast.SpawnExpr) ast.Type {
25842584
// Make sure there are no mutable arguments
25852585
for arg in node.call_expr.args {
25862586
if arg.is_mut && !arg.typ.is_ptr() {
2587+
if arg.typ == 0 {
2588+
c.error('invalid expr', node.pos)
2589+
return 0
2590+
}
25872591
if c.table.final_sym(arg.typ).kind == .array {
25882592
// allow mutable []array to be passed as mut
25892593
continue
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
vlib/v/checker/tests/spawn_wrong_fn_err.vv:29:5: error: unknown function: vlang_ip
2+
27 | wg.add(2)
3+
28 | go vlang_time(mut wg)
4+
29 | go vlang_ip(mut wg)
5+
| ~~~~~~~~~~~~~~~~
6+
30 | wg.wait()
7+
31 | }
8+
vlib/v/checker/tests/spawn_wrong_fn_err.vv:29:5: error: invalid expr
9+
27 | wg.add(2)
10+
28 | go vlang_time(mut wg)
11+
29 | go vlang_ip(mut wg)
12+
| ~~~~~~~~~~~~~~~~
13+
30 | wg.wait()
14+
31 | }
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
import net.http
2+
import sync
3+
import time
4+
5+
fn vlang_time(mut wg sync.WaitGroup) !string {
6+
start := time.ticks()
7+
data := http.get('https://vlang.io/utc_now')!
8+
finish := time.ticks()
9+
println('Finish getting time ${finish - start} ms')
10+
println(data.body)
11+
wg.done()
12+
return data.body
13+
}
14+
15+
fn remote_ip(mut wg sync.WaitGroup) !string {
16+
start := time.ticks()
17+
data := http.get('https://api.ipify.org')!
18+
finish := time.ticks()
19+
println('Finish getting ip ${finish - start} ms')
20+
println(data.body)
21+
wg.done()
22+
return data.body
23+
}
24+
25+
fn main() {
26+
mut wg := sync.new_waitgroup()
27+
wg.add(2)
28+
go vlang_time(mut wg)
29+
go vlang_ip(mut wg)
30+
wg.wait()
31+
}
32+

0 commit comments

Comments
 (0)