blob: 95514cfd650ae6d95c767e040fddc4c02c60c95e [file] [log] [blame]
Russ Coxe0059ae2010-01-18 16:52:18 -08001// $G $D/$F.go && $L $F.$A && ./$A.out
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
7package main
8
Russ Cox6b335712011-03-27 23:39:42 -04009import "os"
10
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 Cox6b335712011-03-27 23:39:42 -040025 var conn, _ = Dial("tcp", "", listen.Addr().String())
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
40func (t T) Addr() os.Error {
Robert Griesemer712fb6d2011-06-22 10:52:47 -070041 return os.NewError("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}