summaryrefslogtreecommitdiff
path: root/test/escape_closure.go
diff options
context:
space:
mode:
authorCherry Zhang <cherryyz@google.com>2020-10-28 09:12:20 -0400
committerCherry Zhang <cherryyz@google.com>2020-10-28 09:12:20 -0400
commita16e30d162c1c7408db7821e7b9513cefa09c6ca (patch)
treeaf752ba9ba44c547df39bb0af9bff79f610ba9d5 /test/escape_closure.go
parent91e4d2d57bc341dd82c98247117114c851380aef (diff)
parentcf6cfba4d5358404dd890f6025e573a4b2156543 (diff)
downloadgo-git-dev.link.tar.gz
[dev.link] all: merge branch 'master' into dev.linkdev.link
Clean merge. Change-Id: Ia7b2808bc649790198d34c226a61d9e569084dc5
Diffstat (limited to 'test/escape_closure.go')
-rw-r--r--test/escape_closure.go17
1 files changed, 15 insertions, 2 deletions
diff --git a/test/escape_closure.go b/test/escape_closure.go
index 3b14027fa4..9152319fe0 100644
--- a/test/escape_closure.go
+++ b/test/escape_closure.go
@@ -50,7 +50,7 @@ func ClosureCallArgs4() {
}
func ClosureCallArgs5() {
- x := 0 // ERROR "moved to heap: x"
+ x := 0 // ERROR "moved to heap: x"
// TODO(mdempsky): We get "leaking param: p" here because the new escape analysis pass
// can tell that p flows directly to sink, but it's a little weird. Re-evaluate.
sink = func(p *int) *int { // ERROR "leaking param: p" "func literal does not escape"
@@ -132,7 +132,7 @@ func ClosureCallArgs14() {
}
func ClosureCallArgs15() {
- x := 0 // ERROR "moved to heap: x"
+ x := 0 // ERROR "moved to heap: x"
p := &x
sink = func(p **int) *int { // ERROR "leaking param content: p" "func literal does not escape"
return *p
@@ -164,3 +164,16 @@ func ClosureLeak2a(a ...string) string { // ERROR "leaking param content: a"
func ClosureLeak2b(f func() string) string { // ERROR "f does not escape"
return f()
}
+
+func ClosureIndirect() {
+ f := func(p *int) {} // ERROR "p does not escape" "func literal does not escape"
+ f(new(int)) // ERROR "new\(int\) does not escape"
+
+ g := f
+ g(new(int)) // ERROR "new\(int\) does not escape"
+
+ h := nopFunc
+ h(new(int)) // ERROR "new\(int\) does not escape"
+}
+
+func nopFunc(p *int) {} // ERROR "p does not escape"