checker: fix array_insert_or_prepend_short_struct_init (#8397)

pull/8421/head
yuyi 2021-01-29 21:53:14 +08:00 committed by GitHub
parent 56c4a36cd4
commit 26c06a56b7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 15 additions and 1 deletions

View File

@ -1239,6 +1239,7 @@ fn (mut c Checker) check_map_and_filter(is_map bool, elem_typ table.Type, call_e
pub fn (mut c Checker) call_method(mut call_expr ast.CallExpr) table.Type {
left_type := c.expr(call_expr.left)
c.expected_type = left_type
is_generic := left_type.has_flag(.generic)
call_expr.left_type = left_type
// Set default values for .return_type & .receiver_type too,

View File

@ -8,5 +8,18 @@ fn test_array_append_short_struct() {
contents: 3
}
println(pages)
assert pages == [Page{ contents: 3}]
assert pages == [Page{contents: 3}]
}
struct Container {
pub mut:
name string
}
fn test_array_insert_or_prepend_short_struct() {
mut a := []Container{}
a.prepend({name: 'a'})
a.insert(0, {name: 'b'})
println(a)
assert a == [Container{name: 'b'}, Container{name: 'a'}]
}