mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
cgen: auto initialize chan
that are struct elements (#8541)
This commit is contained in:
parent
f013e65670
commit
112c652ace
14
vlib/sync/struct_chan_init_test.v
Normal file
14
vlib/sync/struct_chan_init_test.v
Normal file
@ -0,0 +1,14 @@
|
||||
struct Abc {
|
||||
ch chan int
|
||||
}
|
||||
|
||||
fn f(st Abc) {
|
||||
st.ch <- 47
|
||||
}
|
||||
|
||||
fn test_chan_init() {
|
||||
st := Abc{}
|
||||
go f(st)
|
||||
i := <-st.ch
|
||||
assert i == 47
|
||||
}
|
@ -5732,6 +5732,10 @@ fn (mut g Gen) type_default(typ_ table.Type) string {
|
||||
'rune' { return '0' }
|
||||
else {}
|
||||
}
|
||||
if sym.kind == .chan {
|
||||
elemtypstr := g.typ(sym.chan_info().elem_type)
|
||||
return 'sync__new_channel_st(0, sizeof($elemtypstr))'
|
||||
}
|
||||
return match sym.kind {
|
||||
.interface_, .sum_type, .array_fixed, .multi_return { '{0}' }
|
||||
.alias { g.type_default((sym.info as table.Alias).parent_type) }
|
||||
|
Loading…
Reference in New Issue
Block a user