From 4869307ff6c636b983ddb53a8facbe4ea08519cd Mon Sep 17 00:00:00 2001 From: Russ Cox Date: Tue, 28 Jul 2009 20:01:00 -0700 Subject: 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 --- test/closure.go | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'test/closure.go') 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"); + } } -- cgit v1.2.1