Files
moxa/_test/select12.go
Marc Vertes 0ef7f8fb80 fix: perform send channel action for select (#665)
* fix: perform send channel action for select

The CFG was wrong for select send comm clauses. If an init operation
on channel was required (like a derefence, index operation, ...) it
was skipped. The bug was invisible in case of a local var channel.

A send channel init operation consist to prepare both the data to
send (right subtree of send AST) and the channel itself (left
subtree of send AST). All channel init operation must be performed
prior to call select.

Fixes #647.

* doc: fix comment

* invert test to continue early

please note that this also changes the logic a little bit, since the
line that was:

if pn != nil {

now implictly becomes:

if an != nil && pn != nil {

(which I think is actually more correct).

* explicit chaining of init actions in select

* explicit chaining of init actions in select

Co-authored-by: mpl <mathieu.lonjaret@gmail.com>
2020-06-10 11:37:06 +02:00

24 lines
268 B
Go

package main
type S struct {
q chan struct{}
}
func (s *S) Send() {
select {
case s.q <- struct{}{}:
println("sent")
default:
println("unexpected")
}
}
func main() {
s := &S{q: make(chan struct{}, 1)}
s.Send()
println("bye")
}
// Output:
// sent
// bye