From fa447443caab755a132ed4c7d30122defac953df Mon Sep 17 00:00:00 2001 From: yuyi Date: Sat, 20 Aug 2022 00:27:42 +0800 Subject: [PATCH] cgen: fix push on closed channel (#15468) --- vlib/v/gen/c/cgen.v | 4 ++-- vlib/v/tests/inout/push_on_closed_channel.out | 1 + vlib/v/tests/inout/push_on_closed_channel.vv | 7 +++++++ 3 files changed, 10 insertions(+), 2 deletions(-) create mode 100644 vlib/v/tests/inout/push_on_closed_channel.out create mode 100644 vlib/v/tests/inout/push_on_closed_channel.vv diff --git a/vlib/v/gen/c/cgen.v b/vlib/v/gen/c/cgen.v index 7a005cbfe0..b934e9764f 100644 --- a/vlib/v/gen/c/cgen.v +++ b/vlib/v/gen/c/cgen.v @@ -390,8 +390,6 @@ pub fn gen(files []&ast.File, table &ast.Table, pref &pref.Preferences) string { } global_g.gen_jsons() - global_g.write_optionals() - global_g.write_results() global_g.dump_expr_definitions() // this uses global_g.get_str_fn, so it has to go before the below for loop for i := 0; i < global_g.str_types.len; i++ { global_g.final_gen_str(global_g.str_types[i]) @@ -406,6 +404,8 @@ pub fn gen(files []&ast.File, table &ast.Table, pref &pref.Preferences) string { global_g.gen_array_index_methods() global_g.gen_equality_fns() global_g.gen_free_methods() + global_g.write_results() + global_g.write_optionals() global_g.sort_globals_consts() global_g.timers.show('cgen unification') diff --git a/vlib/v/tests/inout/push_on_closed_channel.out b/vlib/v/tests/inout/push_on_closed_channel.out new file mode 100644 index 0000000000..ba70ce13ad --- /dev/null +++ b/vlib/v/tests/inout/push_on_closed_channel.out @@ -0,0 +1 @@ +Channel closed. diff --git a/vlib/v/tests/inout/push_on_closed_channel.vv b/vlib/v/tests/inout/push_on_closed_channel.vv new file mode 100644 index 0000000000..e14670e77a --- /dev/null +++ b/vlib/v/tests/inout/push_on_closed_channel.vv @@ -0,0 +1,7 @@ +module main + +fn main() { + ch := chan int{cap: 100} + ch.close() + ch <- 1 or { println('Channel closed.') } +}