mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
cgen: handle default anonymous structs
This commit is contained in:
parent
1a49db4ea1
commit
70890b27a5
@ -5390,8 +5390,13 @@ fn (mut g Gen) type_default(typ_ ast.Type) string {
|
|||||||
}
|
}
|
||||||
if has_none_zero {
|
if has_none_zero {
|
||||||
init_str += '}'
|
init_str += '}'
|
||||||
type_name := g.typ(typ)
|
type_name := if info.is_anon {
|
||||||
init_str = '($type_name)' + init_str
|
// No name needed for anon structs, C figures it out on its own.
|
||||||
|
''
|
||||||
|
} else {
|
||||||
|
'(${g.typ(typ)})'
|
||||||
|
}
|
||||||
|
init_str = type_name + init_str
|
||||||
} else {
|
} else {
|
||||||
init_str += '0}'
|
init_str += '0}'
|
||||||
}
|
}
|
||||||
|
@ -425,6 +425,9 @@ struct Book {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn test_anon() {
|
fn test_anon() {
|
||||||
// book := Book{author:struct{'sdf', 23}}
|
empty_book := Book{} // author:struct{'sdf', 23}}
|
||||||
// println(book.author.age)
|
assert empty_book.author.age == 0
|
||||||
|
assert empty_book.author.name == ''
|
||||||
|
|
||||||
|
println(empty_book.author.age)
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user