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

checker: fix array append short struct init (#8362)

This commit is contained in:
yuyi 2021-01-27 20:55:53 +08:00 committed by GitHub
parent 2b30c48770
commit d1ab22d45f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 18 additions and 1 deletions

View File

@ -476,7 +476,12 @@ pub fn (mut c Checker) struct_init(mut struct_init ast.StructInit) table.Type {
c.error('unexpected short struct syntax', struct_init.pos)
return table.void_type
}
struct_init.typ = c.expected_type
sym := c.table.get_type_symbol(c.expected_type)
if sym.kind == .array {
struct_init.typ = c.table.value_type(c.expected_type)
} else {
struct_init.typ = c.expected_type
}
}
if struct_init.typ == 0 {
c.error('unknown type', struct_init.pos)

View File

@ -0,0 +1,12 @@
struct Page {
contents int
}
fn test_array_append_short_struct() {
mut pages := []Page{}
pages << {
contents: 3
}
println(pages)
assert pages == [Page{ contents: 3}]
}