Skip to content

Commit 5d36a59

Browse files
checker: fix returning [] from fn which retuns optional array
1 parent 0a03856 commit 5d36a59

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

vlib/v/checker/checker.v

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2985,7 +2985,8 @@ pub fn (mut c Checker) array_init(mut array_init ast.ArrayInit) table.Type {
29852985
// }
29862986
array_info := type_sym.array_info()
29872987
array_init.elem_type = array_info.elem_type
2988-
return c.expected_type
2988+
// clear optional flag incase of: `fn opt_arr ?[]int { return [] }`
2989+
return c.expected_type.clear_flag(.optional)
29892990
}
29902991
// [1,2,3]
29912992
if array_init.exprs.len > 0 && array_init.elem_type == table.void_type {

0 commit comments

Comments
 (0)