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 +}