| 1 |
// errorcheck -0 -l -m |
| 2 |
|
| 3 |
// Copyright 2017 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 |
// Issue 21709: range expression overly escapes. |
| 8 |
|
| 9 |
package p |
| 10 |
|
| 11 |
type S struct{} |
| 12 |
|
| 13 |
func (s *S) Inc() {} // ERROR "s does not escape" |
| 14 |
var N int |
| 15 |
|
| 16 |
func F1() { |
| 17 |
var s S |
| 18 |
for i := 0; i < N; i++ { |
| 19 |
fs := []func(){ // ERROR "\[\]func\(\){...} does not escape" |
| 20 |
s.Inc, // ERROR "s.Inc does not escape" |
| 21 |
} |
| 22 |
for _, f := range fs { |
| 23 |
f() |
| 24 |
} |
| 25 |
} |
| 26 |
} |
| 27 |
|
| 28 |
func F2() { |
| 29 |
var s S |
| 30 |
for i := 0; i < N; i++ { |
| 31 |
for _, f := range []func(){ // ERROR "\[\]func\(\){...} does not escape" |
| 32 |
s.Inc, // ERROR "s.Inc does not escape" |
| 33 |
} { |
| 34 |
f() |
| 35 |
} |
| 36 |
} |
| 37 |
} |