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

checker: fix returning [] from fn which retuns optional array

This commit is contained in:
Joe Conigliaro 2021-02-12 22:30:30 +11:00
parent 0a03856c83
commit 5d36a59dd8
No known key found for this signature in database
GPG Key ID: C12F7136C08206F1

View File

@ -2985,7 +2985,8 @@ pub fn (mut c Checker) array_init(mut array_init ast.ArrayInit) table.Type {
// }
array_info := type_sym.array_info()
array_init.elem_type = array_info.elem_type
return c.expected_type
// clear optional flag incase of: `fn opt_arr ?[]int { return [] }`
return c.expected_type.clear_flag(.optional)
}
// [1,2,3]
if array_init.exprs.len > 0 && array_init.elem_type == table.void_type {