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

checker: fix fn returning ![]string called in main (#16023)

This commit is contained in:
yuyi 2022-10-11 00:41:24 +08:00 committed by GitHub
parent 0f229874a2
commit 89eb8358cf
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 14 additions and 1 deletions

View File

@ -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 {

View File

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