Source file test/fixedbugs/issue43111.go

     1  // run
     2  
     3  // Copyright 2020 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  package main
     8  
     9  var ch chan int
    10  var x int
    11  
    12  func f() int {
    13  	close(ch)
    14  	ch = nil
    15  	return 0
    16  }
    17  
    18  func g() int {
    19  	ch = nil
    20  	x = 0
    21  	return 0
    22  }
    23  
    24  func main() {
    25  	var nilch chan int
    26  	var v int
    27  	var ok bool
    28  	_, _ = v, ok
    29  
    30  	ch = make(chan int)
    31  	select {
    32  	case <-ch:
    33  	case nilch <- f():
    34  	}
    35  
    36  	ch = make(chan int)
    37  	select {
    38  	case v = <-ch:
    39  	case nilch <- f():
    40  	}
    41  
    42  	ch = make(chan int)
    43  	select {
    44  	case v := <-ch: _ = v
    45  	case nilch <- f():
    46  	}
    47  
    48  	ch = make(chan int)
    49  	select {
    50  	case v, ok = <-ch:
    51  	case nilch <- f():
    52  	}
    53  
    54  	ch = make(chan int)
    55  	select {
    56  	case v, ok := <-ch: _, _ = v, ok
    57  	case nilch <- f():
    58  	}
    59  
    60  	ch1 := make(chan int, 1)
    61  	ch = ch1
    62  	x = 42
    63  	select {
    64  	case ch <- x:
    65  	case nilch <- g():
    66  	}
    67  	if got := <-ch1; got != 42 {
    68  		panic(got)
    69  	}
    70  }
    71  

View as plain text