1
0
mirror of https://github.com/golang/go synced 2024-11-26 22:51:23 -07:00
go/test/fixedbugs/issue8336.go
Russ Cox 20e97677fd cmd/gc: fix order of channel evaluation of receive channels
Normally, an expression of the form x.f or *y can be reordered
with function calls and communications.

Select is stricter than normal: each channel expression is evaluated
in source order. If you have case <-x.f and case <-foo(), then if the
evaluation of x.f causes a panic, foo must not have been called.
(This is in contrast to an expression like x.f + foo().)

Enforce this stricter ordering.

Fixes #8336.

LGTM=dvyukov
R=golang-codereviews, dvyukov
CC=golang-codereviews, r
https://golang.org/cl/126570043
2014-08-25 07:05:45 -04:00

30 lines
516 B
Go

// run
// Copyright 2014 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
// Issue 8336. Order of evaluation of receive channels in select.
package main
type X struct {
c chan int
}
func main() {
defer func() {
recover()
}()
var x *X
select {
case <-x.c: // should fault and panic before foo is called
case <-foo():
}
}
func foo() chan int {
println("BUG: foo must not be called")
return make(chan int)
}