From 89eb8358cfd75e840c96c76c042a105adabaf9ef Mon Sep 17 00:00:00 2001 From: yuyi Date: Tue, 11 Oct 2022 00:41:24 +0800 Subject: [PATCH] checker: fix fn returning `![]string` called in main (#16023) --- vlib/v/checker/containers.v | 2 +- vlib/v/tests/fn_return_opt_or_res_of_array_test.v | 13 +++++++++++++ 2 files changed, 14 insertions(+), 1 deletion(-) create mode 100644 vlib/v/tests/fn_return_opt_or_res_of_array_test.v diff --git a/vlib/v/checker/containers.v b/vlib/v/checker/containers.v index f29924c468..e087f8a6b0 100644 --- a/vlib/v/checker/containers.v +++ b/vlib/v/checker/containers.v @@ -121,7 +121,7 @@ pub fn (mut c Checker) array_init(mut node ast.ArrayInit) ast.Type { c.expected_type.clear_flag(.shared_f).deref() } else { c.expected_type - }.clear_flag(.optional) + }.clear_flag(.optional).clear_flag(.result) } // [1,2,3] if node.exprs.len > 0 && node.elem_type == ast.void_type { diff --git a/vlib/v/tests/fn_return_opt_or_res_of_array_test.v b/vlib/v/tests/fn_return_opt_or_res_of_array_test.v new file mode 100644 index 0000000000..c8401c7eaf --- /dev/null +++ b/vlib/v/tests/fn_return_opt_or_res_of_array_test.v @@ -0,0 +1,13 @@ +fn foo_res() ![]string { + return [] +} + +fn foo_opt() ?[]string { + return [] +} + +fn test_fn_return_opt_or_res_of_array() { + foo_res() or { panic(err) } + foo_opt() or { panic(err) } + assert true +}