| 1 |
// errorcheck -0 -l -m |
| 2 |
|
| 3 |
// Copyright 2019 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. |
| 6 |
|
| 7 |
package p |
| 8 |
|
| 9 |
var sink interface{} |
| 10 |
|
| 11 |
func f1() { |
| 12 |
var t T |
| 13 |
f := t.noescape // ERROR "t.noescape does not escape" |
| 14 |
f() |
| 15 |
} |
| 16 |
|
| 17 |
func f2() { |
| 18 |
var t T // ERROR "moved to heap" |
| 19 |
f := t.escape // ERROR "t.escape does not escape" |
| 20 |
f() |
| 21 |
} |
| 22 |
|
| 23 |
func f3() { |
| 24 |
var t T // ERROR "moved to heap" |
| 25 |
f := t.returns // ERROR "t.returns does not escape" |
| 26 |
sink = f() |
| 27 |
} |
| 28 |
|
| 29 |
type T struct{} |
| 30 |
|
| 31 |
func (t *T) noescape() {} // ERROR "t does not escape" |
| 32 |
func (t *T) escape() { sink = t } // ERROR "leaking param: t$" |
| 33 |
func (t *T) returns() *T { return t } // ERROR "leaking param: t to result ~r0 level=0" |
| 34 |
|
| 35 |
func (t *T) recursive() { // ERROR "leaking param: t$" |
| 36 |
sink = t |
| 37 |
|
| 38 |
var t2 T // ERROR "moved to heap" |
| 39 |
f := t2.recursive // ERROR "t2.recursive does not escape" |
| 40 |
f() |
| 41 |
} |