1
0
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:
yuyi 2023-01-17 12:50:11 +08:00 committed by GitHub
parent 1302dbf02f
commit 930e629d2e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 20 additions and 1 deletions

View File

@ -5910,7 +5910,7 @@ fn (mut g Gen) type_default(typ_ ast.Type) string {
for field in info.fields {
field_sym := g.table.sym(field.typ)
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)
if field.has_default_expr {
mut expr_str := ''

View 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}'
}