modernc.org/gc@v1.0.1-0.20240304020402-f0dba7c97c2b/testdata/errchk/test/fixedbugs/bug243.go (about)

     1  // run
     2  
     3  // Copyright 2010 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  import "errors"
    10  
    11  // Issue 481: closures and var declarations
    12  // with multiple variables assigned from one
    13  // function call.
    14  
    15  func main() {
    16  	var listen, _ = Listen("tcp", "127.0.0.1:0")
    17  
    18  	go func() {
    19  		for {
    20  			var conn, _ = listen.Accept()
    21  			_ = conn
    22  		}
    23  	}()
    24  
    25  	var conn, _ = Dial("tcp", "", listen.Addr().Error())
    26  	_ = conn
    27  }
    28  
    29  // Simulated net interface to exercise bug
    30  // without involving a real network.
    31  type T chan int
    32  
    33  var global T
    34  
    35  func Listen(x, y string) (T, string) {
    36  	global = make(chan int)
    37  	return global, y
    38  }
    39  
    40  func (t T) Addr() error {
    41  	return errors.New("stringer")
    42  }
    43  
    44  func (t T) Accept() (int, string) {
    45  	return <-t, ""
    46  }
    47  
    48  func Dial(x, y, z string) (int, string) {
    49  	global <- 1
    50  	return 0, ""
    51  }