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

pull/8729/head
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
1 changed files with 2 additions and 1 deletions

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 {