1 // errorcheck -0 -N -m -l
3 // Copyright 2016 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.
7 // The escape analyzer needs to run till its root set settles
8 // (this is not that often, it turns out).
9 // This test is likely to become stale because the leak depends
10 // on a spurious-escape bug -- return an interface as a named
11 // output parameter appears to cause the called closure to escape,
12 // where returning it as a regular type does not.
20 type closure func(i, j int) ent
24 func (e ent) String() string {
25 return fmt.Sprintf("%d", int(e)) // ERROR "... argument does not escape$" "int\(e\) escapes to heap$"
29 func foo(ops closure, j int) (err fmt.Stringer) { // ERROR "ops does not escape"
30 enqueue := func(i int) fmt.Stringer { // ERROR "func literal does not escape"
31 return ops(i, j) // ERROR "ops\(i, j\) escapes to heap$"
37 return // return result of enqueue, a fmt.Stringer
41 // 3 identical functions, to get different escape behavior.
42 f := func(i, j int) ent { // ERROR "func literal does not escape"
46 fmt.Printf("foo(f,3)=%d\n", int(i)) // ERROR "int\(i\) escapes to heap$" "... argument does not escape$"