summaryrefslogtreecommitdiff
path: root/test/closure.go
diff options
context:
space:
mode:
authorRuss Cox <rsc@golang.org>2009-07-28 20:01:00 -0700
committerRuss Cox <rsc@golang.org>2009-07-28 20:01:00 -0700
commit4869307ff6c636b983ddb53a8facbe4ea08519cd (patch)
tree8a67b2efe49f8ab0283f63357abc34358617d955 /test/closure.go
parentd1b8b013577b54a472f3340d10ce6a5f0b1d8ad5 (diff)
downloadgo-4869307ff6c636b983ddb53a8facbe4ea08519cd.tar.gz
make every func literal expression allocate,
so that == on func means that the functions originated in the same execution of a func literal or definition. before, there was an inconsistency: func() {x++} != func() {x++} but func() {} == func() {} this CL makes the second case != too, just like make(map[int]int) != make(map[int]int) R=r DELTA=202 (71 added, 62 deleted, 69 changed) OCL=32393 CL=32398
Diffstat (limited to 'test/closure.go')
-rw-r--r--test/closure.go12
1 files changed, 12 insertions, 0 deletions
diff --git a/test/closure.go b/test/closure.go
index 97361a1df..8bb516d29 100644
--- a/test/closure.go
+++ b/test/closure.go
@@ -73,6 +73,10 @@ func h() {
f(500);
}
+func newfunc() (func(int) int) {
+ return func(x int) int { return x }
+}
+
func main() {
go f();
@@ -85,4 +89,12 @@ func main() {
go h();
check([]int{100,200,101,201,500,101,201,500});
+
+ x, y := newfunc(), newfunc();
+ if x == y {
+ panicln("newfunc returned same func");
+ }
+ if x(1) != 1 || y(2) != 2 {
+ panicln("newfunc returned broken funcs");
+ }
}