diff --git a/vlib/sync/channel_opt_propagate_test.v b/vlib/sync/channel_opt_propagate_test.v index 42867deef0..4bb4138aee 100644 --- a/vlib/sync/channel_opt_propagate_test.v +++ b/vlib/sync/channel_opt_propagate_test.v @@ -4,13 +4,13 @@ const ( num_iterations = 10000 ) -fn get_val_from_chan(ch chan int) ?int { +fn get_val_from_chan(ch chan i64) ?i64 { r := <-ch ? return r } -// this function gets an array of channels for `int` -fn do_rec_calc_send(chs []chan int, sem sync.Semaphore) { +// this function gets an array of channels for `i64` +fn do_rec_calc_send(chs []chan i64, sem sync.Semaphore) { mut msg := '' for { mut s := get_val_from_chan(chs[0]) or { @@ -25,10 +25,10 @@ fn do_rec_calc_send(chs []chan int, sem sync.Semaphore) { } fn test_channel_array_mut() { - mut chs := [chan int{}, chan int{cap: 10}] + mut chs := [chan i64{}, chan i64{cap: 10}] sem := sync.new_semaphore() go do_rec_calc_send(chs, sem) - mut t := int(100) + mut t := i64(100) for _ in 0 .. num_iterations { chs[0] <- t t = <-chs[1] diff --git a/vlib/sync/channel_push_or_2_test.v b/vlib/sync/channel_push_or_2_test.v index 450a0f605a..7004e2c868 100644 --- a/vlib/sync/channel_push_or_2_test.v +++ b/vlib/sync/channel_push_or_2_test.v @@ -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) } diff --git a/vlib/v/gen/cgen.v b/vlib/v/gen/cgen.v index 44dc7a0487..f09e2d901b 100644 --- a/vlib/v/gen/cgen.v +++ b/vlib/v/gen/cgen.v @@ -5045,7 +5045,10 @@ fn (mut g Gen) or_block(var_name string, or_block ast.OrExpr, return_type table. g.write_defer_stmts() // Now that option types are distinct we need a cast here styp := g.typ(g.fn_decl.return_type) - g.writeln('\treturn *($styp *)&$cvar_name;') + err_obj := g.new_tmp_var() + g.writeln('\t$styp $err_obj;') + g.writeln('\tmemcpy(&$err_obj, &$cvar_name, sizeof(Option));') + g.writeln('\treturn $err_obj;') } } g.write('}')