aboutsummaryrefslogtreecommitdiff
path: root/test/range.go
diff options
context:
space:
mode:
authorMartin Möhrmann <moehrmann@google.com>2017-09-03 08:20:57 +0200
committerMartin Möhrmann <moehrmann@google.com>2017-09-12 05:50:54 +0000
commit137e4a6c63e8688cba34df7dad81b45f0aaa500c (patch)
tree391ea178fd326029bfa5167345768b5797d9fc08 /test/range.go
parent78c4dc37097fa98f73de02ffe1709b776a78354d (diff)
downloadgo-137e4a6c63e8688cba34df7dad81b45f0aaa500c.tar.gz
go-137e4a6c63e8688cba34df7dad81b45f0aaa500c.zip
cmd/compile: improve single blank variable handling in walkrange
Refactor walkrange to treat "for _ = range a" as "for range a". This avoids generating some later discarded nodes in the compiler. Passes toolstash -cmp. Change-Id: Ifb2e1ca3b8519cbb67e8ad5aad514af9d18f1ec4 Reviewed-on: https://go-review.googlesource.com/61017 Run-TryBot: Martin Möhrmann <moehrmann@google.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Keith Randall <khr@golang.org>
Diffstat (limited to 'test/range.go')
-rw-r--r--test/range.go49
1 files changed, 48 insertions, 1 deletions
diff --git a/test/range.go b/test/range.go
index afdac57fa3..3da7d170b5 100644
--- a/test/range.go
+++ b/test/range.go
@@ -23,12 +23,57 @@ func seq(lo, hi int) chan int {
return c
}
+const alphabet = "abcdefghijklmnopqrstuvwxyz"
+
+func testblankvars() {
+ n := 0
+ for range alphabet {
+ n++
+ }
+ if n != 26 {
+ println("for range: wrong count", n, "want 26")
+ panic("fail")
+ }
+ n = 0
+ for _ = range alphabet {
+ n++
+ }
+ if n != 26 {
+ println("for _ = range: wrong count", n, "want 26")
+ panic("fail")
+ }
+ n = 0
+ for _, _ = range alphabet {
+ n++
+ }
+ if n != 26 {
+ println("for _, _ = range: wrong count", n, "want 26")
+ panic("fail")
+ }
+ s := 0
+ for i, _ := range alphabet {
+ s += i
+ }
+ if s != 325 {
+ println("for i, _ := range: wrong sum", s, "want 325")
+ panic("fail")
+ }
+ r := rune(0)
+ for _, v := range alphabet {
+ r += v
+ }
+ if r != 2847 {
+ println("for _, v := range: wrong sum", r, "want 2847")
+ panic("fail")
+ }
+}
+
func testchan() {
s := ""
for i := range seq('a', 'z') {
s += string(i)
}
- if s != "abcdefghijklmnopqrstuvwxyz" {
+ if s != alphabet {
println("Wanted lowercase alphabet; got", s)
panic("fail")
}
@@ -38,6 +83,7 @@ func testchan() {
}
if n != 26 {
println("testchan wrong count", n, "want 26")
+ panic("fail")
}
}
@@ -426,6 +472,7 @@ func testcalls() {
}
func main() {
+ testblankvars()
testchan()
testarray()
testarray1()