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:
parent
2b30c48770
commit
d1ab22d45f
@ -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)
|
||||
|
12
vlib/v/tests/array_append_short_struct_test.v
Normal file
12
vlib/v/tests/array_append_short_struct_test.v
Normal 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}]
|
||||
}
|
Loading…
Reference in New Issue
Block a user