mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
cgen: fix option ptr default struct initialization (#18141)
This commit is contained in:
parent
9aa5e3fe4b
commit
0be74aa613
@ -321,7 +321,7 @@ fn (mut g Gen) zero_struct_field(field ast.StructField) bool {
|
|||||||
}
|
}
|
||||||
g.write('.${field_name} = ')
|
g.write('.${field_name} = ')
|
||||||
if field.typ.has_flag(.option) {
|
if field.typ.has_flag(.option) {
|
||||||
if field.is_recursive {
|
if field.is_recursive || field.typ.is_ptr() {
|
||||||
g.expr_with_opt(ast.None{}, ast.none_type, field.typ)
|
g.expr_with_opt(ast.None{}, ast.none_type, field.typ)
|
||||||
} else {
|
} else {
|
||||||
tmp_var := g.new_tmp_var()
|
tmp_var := g.new_tmp_var()
|
||||||
|
12
vlib/v/tests/option_ptr_init_test.v
Normal file
12
vlib/v/tests/option_ptr_init_test.v
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
struct Queue {
|
||||||
|
head ?&Node
|
||||||
|
}
|
||||||
|
|
||||||
|
struct Node {
|
||||||
|
next ?&Node
|
||||||
|
}
|
||||||
|
|
||||||
|
fn test_main() {
|
||||||
|
q := Queue{}
|
||||||
|
assert q.head == none
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user