-
Notifications
You must be signed in to change notification settings - Fork 356
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
automatic loop variables in for loops ("loop var"), consistent with g…
…o 1.22 behavior This builds on #1644 and adds automatic per-loop variables that are consistent with go 1.22 behavior. See #1643 for discussion. This is still a draft because the for7 version ends up capturing the per-loop var values when they are +1 relative to what they should be. Maybe somehow the incrementing and conditional code is somehow capturing the within loop variables and incrementing them? not sure how that would work. anyway, need to investigate further before this is ready to go, but pushing it here in case there are other issues or someone might figure out this bug before I do..
- Loading branch information
Showing
18 changed files
with
320 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,6 +13,6 @@ func main() { | |
} | ||
|
||
// Output: | ||
// 3 0 0 | ||
// 3 1 1 | ||
// 3 2 2 | ||
// 0 0 0 | ||
// 1 1 1 | ||
// 2 2 2 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,6 +17,6 @@ func main() { | |
} | ||
|
||
// Output: | ||
// 3 0 | ||
// 3 1 | ||
// 3 2 | ||
// 0 0 | ||
// 1 1 | ||
// 2 2 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -20,6 +20,6 @@ func main() { | |
} | ||
|
||
// Output: | ||
// 3 0 i=0 | ||
// 3 1 i=1 | ||
// 3 2 i=2 | ||
// 0 0 i=0 | ||
// 1 1 i=1 | ||
// 2 2 i=2 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
package main | ||
|
||
func main() { | ||
foos := []func(){} | ||
|
||
for i := range 3 { | ||
a := i | ||
foos = append(foos, func() { println(i, a) }) | ||
} | ||
foos[0]() | ||
foos[1]() | ||
foos[2]() | ||
} | ||
|
||
// Output: | ||
// 0 0 | ||
// 1 1 | ||
// 2 2 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
package main | ||
|
||
func main() { | ||
foos := []func(){} | ||
|
||
for i := range 3 { | ||
a, b := i, i | ||
foos = append(foos, func() { println(i, a, b) }) | ||
} | ||
foos[0]() | ||
foos[1]() | ||
foos[2]() | ||
} | ||
|
||
// Output: | ||
// 0 0 0 | ||
// 1 1 1 | ||
// 2 2 2 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
package main | ||
|
||
type T struct { | ||
F func() | ||
} | ||
|
||
func main() { | ||
foos := []T{} | ||
|
||
for i := range 3 { | ||
a := i | ||
foos = append(foos, T{func() { println(i, a) }}) | ||
} | ||
foos[0].F() | ||
foos[1].F() | ||
foos[2].F() | ||
} | ||
|
||
// Output: | ||
// 0 0 | ||
// 1 1 | ||
// 2 2 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
package main | ||
|
||
import "fmt" | ||
|
||
type T struct { | ||
F func() | ||
} | ||
|
||
func main() { | ||
foos := []T{} | ||
|
||
for i := range 3 { | ||
a := i | ||
n := fmt.Sprintf("i=%d", i) | ||
foos = append(foos, T{func() { println(i, a, n) }}) | ||
} | ||
foos[0].F() | ||
foos[1].F() | ||
foos[2].F() | ||
} | ||
|
||
// Output: | ||
// 0 0 i=0 | ||
// 1 1 i=1 | ||
// 2 2 i=2 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
package main | ||
|
||
func main() { | ||
foos := []func(){} | ||
|
||
for i := 0; i < 3; i++ { | ||
i := i | ||
foos = append(foos, func() { println(i) }) | ||
} | ||
foos[0]() | ||
foos[1]() | ||
foos[2]() | ||
} | ||
|
||
// Output: | ||
// 0 | ||
// 1 | ||
// 2 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
package main | ||
|
||
func main() { | ||
foos := []func(){} | ||
|
||
for i := range 3 { | ||
i := i | ||
foos = append(foos, func() { println(i) }) | ||
} | ||
foos[0]() | ||
foos[1]() | ||
foos[2]() | ||
} | ||
|
||
// Output: | ||
// 0 | ||
// 1 | ||
// 2 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,6 +13,6 @@ func main() { | |
} | ||
|
||
// Output: | ||
// 3 0 | ||
// 3 1 | ||
// 3 2 | ||
// 0 0 | ||
// 1 1 | ||
// 2 2 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package main | ||
|
||
func main() { | ||
mx := 3 | ||
for i := range mx { | ||
println(i) | ||
} | ||
} | ||
|
||
// Output: | ||
// 0 | ||
// 1 | ||
// 2 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
package main | ||
|
||
func main() { | ||
for i := range 3 { | ||
println(i) | ||
} | ||
} | ||
|
||
// Output: | ||
// 0 | ||
// 1 | ||
// 2 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
package main | ||
|
||
func main() { | ||
for range 3 { | ||
println("i") | ||
} | ||
} | ||
|
||
// Output: | ||
// i | ||
// i | ||
// i |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.