Source file test/fixedbugs/issue4313.go

     1  // run
     2  
     3  // Copyright 2012 The Go Authors. All rights reserved.
     4  // Use of this source code is governed by a BSD-style
     5  // license that can be found in the LICENSE file.
     6  
     7  // Order of operations in select.
     8  
     9  package main
    10  
    11  func main() {
    12  	c := make(chan int, 1)
    13  	x := 0
    14  	select {
    15  	case c <- x: // should see x = 0, not x = 42 (after makec)
    16  	case <-makec(&x): // should be evaluated only after c and x on previous line
    17  	}
    18  	y := <-c
    19  	if y != 0 {
    20  		panic(y)
    21  	}
    22  }
    23  
    24  func makec(px *int) chan bool {
    25  	if false { for {} }
    26  	*px = 42
    27  	return make(chan bool, 0)
    28  }
    29  

View as plain text