modernc.org/gc@v1.0.1-0.20240304020402-f0dba7c97c2b/testdata/errchk/test/fixedbugs/issue21709.go (about) 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\).Inc s does not escape" 14 var N int 15 16 func F1() { 17 var s S // ERROR "moved to heap: s" 18 for i := 0; i < N; i++ { 19 fs := []func(){ // ERROR "F1 \[\]func\(\) literal does not escape" 20 s.Inc, // ERROR "F1 s.Inc does not escape" "s escapes to heap" 21 } 22 for _, f := range fs { 23 f() 24 } 25 } 26 } 27 28 func F2() { 29 var s S // ERROR "moved to heap: s" 30 for i := 0; i < N; i++ { 31 for _, f := range []func(){ // ERROR "F2 \[\]func\(\) literal does not escape" 32 s.Inc, // ERROR "F2 s.Inc does not escape" "s escapes to heap" 33 } { 34 f() 35 } 36 } 37 }