Black Lives Matter. Support the Equal Justice Initiative.

Source file src/cmd/vet/testdata/rangeloop/rangeloop.go

Documentation: cmd/vet/testdata/rangeloop

     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  
     5  // This file contains tests for the rangeloop checker.
     6  
     7  package rangeloop
     8  
     9  func RangeLoopTests() {
    10  	var s []int
    11  	for i, v := range s {
    12  		go func() {
    13  			println(i) // ERROR "loop variable i captured by func literal"
    14  			println(v) // ERROR "loop variable v captured by func literal"
    15  		}()
    16  	}
    17  }
    18  

View as plain text