mirror of
https://github.com/vlang/v.git
synced 2025-09-15 10:27:19 -04:00
checker: fix spawn when calling undefined function (#21906)
This commit is contained in:
parent
22df56facd
commit
6e8124fdf9
@ -2584,6 +2584,10 @@ fn (mut c Checker) spawn_expr(mut node ast.SpawnExpr) ast.Type {
|
|||||||
// Make sure there are no mutable arguments
|
// Make sure there are no mutable arguments
|
||||||
for arg in node.call_expr.args {
|
for arg in node.call_expr.args {
|
||||||
if arg.is_mut && !arg.typ.is_ptr() {
|
if arg.is_mut && !arg.typ.is_ptr() {
|
||||||
|
if arg.typ == 0 {
|
||||||
|
c.error('invalid expr', node.pos)
|
||||||
|
return 0
|
||||||
|
}
|
||||||
if c.table.final_sym(arg.typ).kind == .array {
|
if c.table.final_sym(arg.typ).kind == .array {
|
||||||
// allow mutable []array to be passed as mut
|
// allow mutable []array to be passed as mut
|
||||||
continue
|
continue
|
||||||
|
14
vlib/v/checker/tests/spawn_wrong_fn_err.out
Normal file
14
vlib/v/checker/tests/spawn_wrong_fn_err.out
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
vlib/v/checker/tests/spawn_wrong_fn_err.vv:29:5: error: unknown function: vlang_ip
|
||||||
|
27 | wg.add(2)
|
||||||
|
28 | go vlang_time(mut wg)
|
||||||
|
29 | go vlang_ip(mut wg)
|
||||||
|
| ~~~~~~~~~~~~~~~~
|
||||||
|
30 | wg.wait()
|
||||||
|
31 | }
|
||||||
|
vlib/v/checker/tests/spawn_wrong_fn_err.vv:29:5: error: invalid expr
|
||||||
|
27 | wg.add(2)
|
||||||
|
28 | go vlang_time(mut wg)
|
||||||
|
29 | go vlang_ip(mut wg)
|
||||||
|
| ~~~~~~~~~~~~~~~~
|
||||||
|
30 | wg.wait()
|
||||||
|
31 | }
|
32
vlib/v/checker/tests/spawn_wrong_fn_err.vv
Normal file
32
vlib/v/checker/tests/spawn_wrong_fn_err.vv
Normal file
@ -0,0 +1,32 @@
|
|||||||
|
import net.http
|
||||||
|
import sync
|
||||||
|
import time
|
||||||
|
|
||||||
|
fn vlang_time(mut wg sync.WaitGroup) !string {
|
||||||
|
start := time.ticks()
|
||||||
|
data := http.get('https://vlang.io/utc_now')!
|
||||||
|
finish := time.ticks()
|
||||||
|
println('Finish getting time ${finish - start} ms')
|
||||||
|
println(data.body)
|
||||||
|
wg.done()
|
||||||
|
return data.body
|
||||||
|
}
|
||||||
|
|
||||||
|
fn remote_ip(mut wg sync.WaitGroup) !string {
|
||||||
|
start := time.ticks()
|
||||||
|
data := http.get('https://api.ipify.org')!
|
||||||
|
finish := time.ticks()
|
||||||
|
println('Finish getting ip ${finish - start} ms')
|
||||||
|
println(data.body)
|
||||||
|
wg.done()
|
||||||
|
return data.body
|
||||||
|
}
|
||||||
|
|
||||||
|
fn main() {
|
||||||
|
mut wg := sync.new_waitgroup()
|
||||||
|
wg.add(2)
|
||||||
|
go vlang_time(mut wg)
|
||||||
|
go vlang_ip(mut wg)
|
||||||
|
wg.wait()
|
||||||
|
}
|
||||||
|
|
Loading…
x
Reference in New Issue
Block a user