File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -473,6 +473,12 @@ fn (mut g Gen) zero_struct_field(field ast.StructField) bool {
473473 field_name := if sym.language == .v { c_name (field.name) } else { field.name }
474474 if sym.info is ast.Struct {
475475 if sym.info.fields.len == 0 {
476+ // For empty struct fields, check if it's a shared field
477+ if field.typ.has_flag (.shared_f) {
478+ g.write ('.${field_name } = ' )
479+ g.init_shared_field (field)
480+ return true
481+ }
476482 return false
477483 } else if ! field.has_default_expr {
478484 mut has_option_field := false
Original file line number Diff line number Diff line change @@ -168,3 +168,21 @@ fn test_array_of_shared() {
168168 assert e == 3
169169 assert f == - 17
170170}
171+
172+ // Test for issue #16234: empty shared struct initialized as null causing segmentation fault
173+ struct EmptyStruct {}
174+
175+ struct OwnerWithEmptyShared {
176+ empty EmptyStruct
177+ lck shared EmptyStruct
178+ }
179+
180+ fn test_shared_empty_struct () {
181+ mut i := OwnerWithEmptyShared{}
182+ dump (i)
183+ // Test that we can lock the empty shared struct without segfault
184+ lock i.lck {
185+ // Empty struct, nothing to do
186+ }
187+ assert true
188+ }
You can’t perform that action at this time.
0 commit comments