mirror of
https://github.com/golang/go
synced 2024-11-21 23:24:41 -07:00
gc: test that asserts closures are not wrapped when they don't have closure vars.
R=rsc, bradfitz CC=golang-dev https://golang.org/cl/5529060
This commit is contained in:
parent
97fd7d5f34
commit
25cf9bdea6
@ -6,6 +6,8 @@
|
|||||||
|
|
||||||
package main
|
package main
|
||||||
|
|
||||||
|
import "runtime"
|
||||||
|
|
||||||
var c = make(chan int)
|
var c = make(chan int)
|
||||||
|
|
||||||
func check(a []int) {
|
func check(a []int) {
|
||||||
@ -77,6 +79,8 @@ func h() {
|
|||||||
func newfunc() func(int) int { return func(x int) int { return x } }
|
func newfunc() func(int) int { return func(x int) int { return x } }
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
|
var fail bool
|
||||||
|
|
||||||
go f()
|
go f()
|
||||||
check([]int{1, 4, 5, 4})
|
check([]int{1, 4, 5, 4})
|
||||||
|
|
||||||
@ -88,13 +92,26 @@ func main() {
|
|||||||
go h()
|
go h()
|
||||||
check([]int{100, 200, 101, 201, 500, 101, 201, 500})
|
check([]int{100, 200, 101, 201, 500, 101, 201, 500})
|
||||||
|
|
||||||
|
runtime.UpdateMemStats()
|
||||||
|
n0 := runtime.MemStats.Mallocs
|
||||||
|
|
||||||
x, y := newfunc(), newfunc()
|
x, y := newfunc(), newfunc()
|
||||||
if x(1) != 1 || y(2) != 2 {
|
if x(1) != 1 || y(2) != 2 {
|
||||||
println("newfunc returned broken funcs")
|
println("newfunc returned broken funcs")
|
||||||
panic("fail")
|
fail = true
|
||||||
|
}
|
||||||
|
|
||||||
|
runtime.UpdateMemStats()
|
||||||
|
if n0 != runtime.MemStats.Mallocs {
|
||||||
|
println("newfunc allocated unexpectedly")
|
||||||
|
fail = true
|
||||||
}
|
}
|
||||||
|
|
||||||
ff(1)
|
ff(1)
|
||||||
|
|
||||||
|
if fail {
|
||||||
|
panic("fail")
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func ff(x int) {
|
func ff(x int) {
|
||||||
|
Loading…
Reference in New Issue
Block a user