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

cgen: fix address violations for error propagation (#7972)

This commit is contained in:
Uwe Krüger
2021-01-09 02:43:48 +01:00
committed by GitHub
parent bbac95a438
commit eff757d0a1
3 changed files with 17 additions and 14 deletions

View File

@@ -1,27 +1,27 @@
const n = 1000
fn f(ch chan int) {
mut s := 0
fn f(ch chan f64) {
mut s := 0.
for _ in 0 .. n {
s += <-ch
}
assert s == n * (n + 1) / 2
assert s == f64(n * (n + 1) / 2)
ch.close()
}
fn do_send(ch chan int, val int) ?int {
fn do_send(ch chan f64, val f64) ?f64 {
ch <- val ?
return val + 1
return val + 1.0
}
fn test_push_propargate() {
ch := chan int{}
ch := chan f64{}
go f(ch)
mut s := 1
mut s := 1.0
for {
s = do_send(ch, s) or {
break
}
}
assert s == n + 1
assert s == f64(n + 1)
}