2017-11-29 13:55:40 -07:00
|
|
|
// errorcheck -0 -l -m
|
|
|
|
|
|
|
|
// Copyright 2017 The Go Authors. All rights reserved.
|
|
|
|
// Use of this source code is governed by a BSD-style
|
|
|
|
// license that can be found in the LICENSE file.
|
|
|
|
|
|
|
|
// Issue 21709: range expression overly escapes.
|
|
|
|
|
|
|
|
package p
|
|
|
|
|
|
|
|
type S struct{}
|
|
|
|
|
2019-09-12 11:18:03 -06:00
|
|
|
func (s *S) Inc() {} // ERROR "s does not escape"
|
2017-11-29 13:55:40 -07:00
|
|
|
var N int
|
|
|
|
|
|
|
|
func F1() {
|
2020-04-20 12:14:36 -06:00
|
|
|
var s S
|
2017-11-29 13:55:40 -07:00
|
|
|
for i := 0; i < N; i++ {
|
2020-09-08 22:09:01 -06:00
|
|
|
fs := []func(){ // ERROR "\[\]func\(\){...} does not escape"
|
2019-09-12 11:18:03 -06:00
|
|
|
s.Inc, // ERROR "s.Inc does not escape"
|
2017-11-29 13:55:40 -07:00
|
|
|
}
|
|
|
|
for _, f := range fs {
|
|
|
|
f()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func F2() {
|
2020-04-20 12:14:36 -06:00
|
|
|
var s S
|
2017-11-29 13:55:40 -07:00
|
|
|
for i := 0; i < N; i++ {
|
2020-09-08 22:09:01 -06:00
|
|
|
for _, f := range []func(){ // ERROR "\[\]func\(\){...} does not escape"
|
2019-09-12 11:18:03 -06:00
|
|
|
s.Inc, // ERROR "s.Inc does not escape"
|
2017-11-29 13:55:40 -07:00
|
|
|
} {
|
|
|
|
f()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|