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

handle empty config structs

This commit is contained in:
Alexander Medvednikov
2020-01-24 18:57:32 +01:00
parent 2897bac549
commit f55646746c
3 changed files with 25 additions and 1 deletions

View File

@ -493,10 +493,19 @@ fn (p mut Parser) gen_struct_init(typ string, t &Type) bool {
if typ == 'tm' {
p.cgen.lines[p.cgen.lines.len - 1] = ''
}
mut is_config := false
if p.tok != .lcbr {
p.next()
} else {
is_config = true
}
p.check(.lcbr)
// Handle empty config ({})
if is_config && p.tok == .rcbr {
p.check(.rcbr)
p.gen('($typ) {}')
return true
}
ptr := typ.contains('*')
// `user := User{foo:bar}` => `User user = (User){ .foo = bar}`
if !ptr {