mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
This commit is contained in:
parent
1e416de627
commit
9826310882
@ -323,7 +323,12 @@ fn (mut g Gen) zero_struct_field(field ast.StructField) bool {
|
||||
typ: field.typ
|
||||
}
|
||||
g.write('.${field_name} = ')
|
||||
g.struct_init(default_init)
|
||||
if field.typ.has_flag(.option) {
|
||||
tmp_var := g.new_tmp_var()
|
||||
g.expr_with_tmp_var(default_init, field.typ, field.typ, tmp_var)
|
||||
} else {
|
||||
g.struct_init(default_init)
|
||||
}
|
||||
return true
|
||||
}
|
||||
}
|
||||
|
@ -1,22 +1,20 @@
|
||||
struct Foo {
|
||||
a int
|
||||
b int
|
||||
c int
|
||||
pub struct MyStruct {
|
||||
pub mut:
|
||||
valueb ?int
|
||||
}
|
||||
|
||||
struct Holder {
|
||||
mut:
|
||||
i int
|
||||
pub struct MyStruct2 {
|
||||
pub mut:
|
||||
valuea int
|
||||
valueb ?MyStruct
|
||||
}
|
||||
|
||||
fn add(mut h Holder) ?int {
|
||||
h.i++
|
||||
return h.i
|
||||
}
|
||||
|
||||
fn test_struct_init_with_multiple_options() {
|
||||
mut h := Holder{}
|
||||
foo := Foo{add(mut h) or { 0 }, add(mut h) or { 0 }, add(mut h) or { 0 }}
|
||||
|
||||
assert foo == Foo{1, 2, 3}
|
||||
fn test_main() {
|
||||
a := MyStruct2{
|
||||
valuea: 1
|
||||
}
|
||||
assert a.str() == 'MyStruct2{
|
||||
valuea: 1
|
||||
valueb: Option(error: none)
|
||||
}'
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user