1
0
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:
Felipe Pena 2023-05-09 15:40:51 -03:00 committed by GitHub
parent 9aa5e3fe4b
commit 0be74aa613
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 13 additions and 1 deletions

View File

@ -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()

View File

@ -0,0 +1,12 @@
struct Queue {
head ?&Node
}
struct Node {
next ?&Node
}
fn test_main() {
q := Queue{}
assert q.head == none
}