cgen: auto initialize `chan` that are struct elements (#8541)
parent
f013e65670
commit
112c652ace
|
@ -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