modernc.org/gc@v1.0.1-0.20240304020402-f0dba7c97c2b/testdata/errchk/test/fixedbugs/issue17449.go (about) 1 // errorcheck -0 -race 2 3 // Copyright 2016 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 17449: race instrumentation copies over previous instrumented nodes from parents block into child's Ninit block. 8 // This code surfaces the duplication at compile time because of generated inline labels. 9 10 package master 11 12 type PriorityList struct { 13 elems []interface{} 14 } 15 16 func (x *PriorityList) Len() int { return len(x.elems) } 17 18 func (l *PriorityList) remove(i int) interface{} { 19 elem := l.elems[i] 20 l.elems = append(l.elems[:i], l.elems[i+1:]...) 21 return elem 22 } 23 24 func (l *PriorityList) Next() interface{} { 25 return l.remove(l.Len() - 1) 26 } 27 28 var l *PriorityList 29 30 func Foo() { 31 // It would fail here if instrumented code (including inline-label) was copied. 32 for elem := l.Next(); elem != nil; elem = l.Next() { 33 } 34 }