checker: fix spawn when calling undefined function (#21906)

This commit is contained in:
Felipe Pena 2024-07-23 02:48:44 -03:00 committed by GitHub
parent 22df56facd
commit 6e8124fdf9
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 50 additions and 0 deletions

View File

@ -2584,6 +2584,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 arg.typ == 0 {
c.error('invalid expr', node.pos)
return 0
}
if c.table.final_sym(arg.typ).kind == .array {
// allow mutable []array to be passed as mut
continue

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

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