1
0
mirror of https://github.com/vlang/v.git synced 2023-08-10 21:13:21 +03:00

cgen: fix shared struct field initialization with default value (#18075)

This commit is contained in:
Felipe Pena 2023-04-28 10:59:18 -03:00 committed by GitHub
parent b0589c645d
commit b6bbd2463c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 14 additions and 4 deletions

View File

@ -161,9 +161,7 @@ fn (mut g Gen) struct_init(node ast.StructInit) {
g.is_shared = old_is_shared2
}
for mut field in info.fields {
if !field.typ.has_flag(.shared_f) {
g.is_shared = false
}
g.is_shared = field.typ.has_flag(.shared_f)
if mut sym.info is ast.Struct {
mut found_equal_fields := 0
for mut sifield in sym.info.fields {
@ -280,7 +278,6 @@ fn (mut g Gen) struct_init(node ast.StructInit) {
g.write(',')
}
initialized = true
g.is_shared = old_is_shared
}
g.is_shared = old_is_shared
}

View File

@ -0,0 +1,13 @@
module main
struct StructA {
ints shared []int = [0]
}
fn test_main() {
a := StructA{}
rlock a.ints {
dump(a)
assert true
}
}