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.
5 // This file contains tests for the rangeloop checker.
9 func RangeLoopTests() {
13 println(i
) // ERROR "loop variable i captured by func literal"
14 println(v
) // ERROR "loop variable v captured by func literal"
19 println(i
) // ERROR "loop variable i captured by func literal"
20 println(v
) // ERROR "loop variable v captured by func literal"
25 println(i
) // ERROR "loop variable i captured by func literal"
30 println(v
) // ERROR "loop variable v captured by func literal"
37 println("unfortunately, we don't catch the error above because of this statement")
50 // If the key of the range statement is not an identifier
51 // the code should not panic (it used to).
54 for x
[0], f
= range s
{
56 _
= f
// ERROR "loop variable f captured by func literal"
65 _
= []int{v
: 1} // ERROR "loop variable v captured by func literal"
70 for i
:= 0; i
< 10; i
++ {
72 print(i
) // ERROR "loop variable i captured by func literal"
75 for i
, j
:= 0, 1; i
< 100; i
, j
= j
, i
+j
{
77 print(j
) // ERROR "loop variable j captured by func literal"
85 for p
:= head
; p
!= nil; p
= p
.next
{
87 print(p
.car
) // ERROR "loop variable p captured by func literal"