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:
parent
b0589c645d
commit
b6bbd2463c
@ -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
|
||||
}
|
||||
|
13
vlib/v/tests/shared_struct_field_test.v
Normal file
13
vlib/v/tests/shared_struct_field_test.v
Normal 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
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user