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

checker: fix comptime if expr of sync.threads (#12356)

This commit is contained in:
yuyi 2021-11-01 15:41:04 +08:00 committed by GitHub
parent 51f5841b6e
commit da65680acf
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 28 additions and 1 deletions

View File

@ -4500,7 +4500,7 @@ fn (mut c Checker) stmt(node ast.Stmt) {
stmt_pos := node.pos
eprintln('checking file: ${c.file.path:-30} | stmt pos: ${stmt_pos.str():-45} | stmt')
}
// c.expected_type = ast.void_type
c.expected_type = ast.void_type
match mut node {
ast.EmptyStmt {
if c.pref.is_verbose {

View File

@ -0,0 +1,27 @@
import math { floor, sqrt }
import arrays { sum }
fn async(arr_size int, init_val f64) f64 {
mut val_arr := []f64{}
for _ in 1 .. arr_size {
val_arr << floor((sqrt(init_val) / 2) * 3)
}
return sum(val_arr.map(it / 2)) or { f64(1) }
}
fn test_comptime_if_expr_of_threads() {
size := 2000_000
println('Async')
mut results := []thread f64{cap: 16}
for num in 0 .. 15 {
results << go async(size, num)
}
waited_results := results.wait()
println(waited_results)
sum_result := sum(waited_results) or { 1 }
println(sum_result)
assert sum_result == 4.7999976e+07
}