rangeloop.go 452 B

1234567891011121314151617
  1. // Copyright 2012 The Go Authors. All rights reserved.
  2. // Use of this source code is governed by a BSD-style
  3. // license that can be found in the LICENSE file.
  4. // This file contains tests for the rangeloop checker.
  5. package rangeloop
  6. func RangeLoopTests() {
  7. var s []int
  8. for i, v := range s {
  9. go func() {
  10. println(i) // ERROR "loop variable i captured by func literal"
  11. println(v) // ERROR "loop variable v captured by func literal"
  12. }()
  13. }
  14. }