Skip to content

Commit

Permalink
checker: fix spawn when calling undefined function (#21906)
Browse files Browse the repository at this point in the history
  • Loading branch information
felipensp authored Jul 23, 2024
1 parent 22df56f commit 6e8124f
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 0 deletions.
4 changes: 4 additions & 0 deletions vlib/v/checker/fn.v
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
14 changes: 14 additions & 0 deletions vlib/v/checker/tests/spawn_wrong_fn_err.out
Original file line number Diff line number Diff line change
@@ -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 changes: 32 additions & 0 deletions vlib/v/checker/tests/spawn_wrong_fn_err.vv
Original file line number Diff line number Diff line change
@@ -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()
}

0 comments on commit 6e8124f

Please sign in to comment.