mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
cgen: fix struct init with chan field (#17001)
This commit is contained in:
parent
1302dbf02f
commit
930e629d2e
@ -5910,7 +5910,7 @@ fn (mut g Gen) type_default(typ_ ast.Type) string {
|
|||||||
for field in info.fields {
|
for field in info.fields {
|
||||||
field_sym := g.table.sym(field.typ)
|
field_sym := g.table.sym(field.typ)
|
||||||
if field.has_default_expr
|
if field.has_default_expr
|
||||||
|| field_sym.kind in [.array, .map, .string, .bool, .alias, .i8, .i16, .int, .i64, .u8, .u16, .u32, .u64, .char, .voidptr, .byteptr, .charptr, .struct_] {
|
|| field_sym.kind in [.array, .map, .string, .bool, .alias, .i8, .i16, .int, .i64, .u8, .u16, .u32, .u64, .char, .voidptr, .byteptr, .charptr, .struct_, .chan] {
|
||||||
field_name := c_name(field.name)
|
field_name := c_name(field.name)
|
||||||
if field.has_default_expr {
|
if field.has_default_expr {
|
||||||
mut expr_str := ''
|
mut expr_str := ''
|
||||||
|
19
vlib/v/tests/struct_init_with_chan_field_test.v
Normal file
19
vlib/v/tests/struct_init_with_chan_field_test.v
Normal file
@ -0,0 +1,19 @@
|
|||||||
|
struct Abc {
|
||||||
|
def Def
|
||||||
|
}
|
||||||
|
|
||||||
|
struct Def {
|
||||||
|
ch chan string
|
||||||
|
}
|
||||||
|
|
||||||
|
fn test_struct_init_with_chan_field() {
|
||||||
|
abc1 := Abc{Def{}}
|
||||||
|
println('printing abc1')
|
||||||
|
println(abc1) // this works
|
||||||
|
|
||||||
|
abc2 := Abc{}
|
||||||
|
println('printing abc2')
|
||||||
|
println(abc2) // this gives invalid memory access
|
||||||
|
|
||||||
|
assert '${abc1}' == '${abc2}'
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user