blob: 4870c3614cbf74eb54c2d1f79a71829552bb0061 [file] [log] [blame]
Russ Cox80803842012-02-16 23:49:59 -05001// run
Russ Coxe0059ae2010-01-18 16:52:18 -08002
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
7package main
8
Russ Cox44526cd2011-11-01 22:06:05 -04009import "errors"
Russ Cox6b335712011-03-27 23:39:42 -040010
11// Issue 481: closures and var declarations
12// with multiple variables assigned from one
13// function call.
Russ Coxe0059ae2010-01-18 16:52:18 -080014
15func main() {
Russ Cox6b335712011-03-27 23:39:42 -040016 var listen, _ = Listen("tcp", "127.0.0.1:0")
Russ Coxe0059ae2010-01-18 16:52:18 -080017
18 go func() {
19 for {
20 var conn, _ = listen.Accept()
Robert Griesemerbebd22f2010-07-12 14:53:28 -070021 _ = conn
Russ Coxe0059ae2010-01-18 16:52:18 -080022 }
23 }()
24
Russ Cox44526cd2011-11-01 22:06:05 -040025 var conn, _ = Dial("tcp", "", listen.Addr().Error())
Robert Griesemerbebd22f2010-07-12 14:53:28 -070026 _ = conn
Russ Coxe0059ae2010-01-18 16:52:18 -080027}
Russ Cox6b335712011-03-27 23:39:42 -040028
29// Simulated net interface to exercise bug
30// without involving a real network.
31type T chan int
32
33var global T
34
35func Listen(x, y string) (T, string) {
36 global = make(chan int)
37 return global, y
38}
39
Russ Cox44526cd2011-11-01 22:06:05 -040040func (t T) Addr() error {
41 return errors.New("stringer")
Russ Cox6b335712011-03-27 23:39:42 -040042}
43
44func (t T) Accept() (int, string) {
45 return <-t, ""
46}
47
48func Dial(x, y, z string) (int, string) {
49 global <- 1
50 return 0, ""
51}