diff options
| author | David Chase <drchase@google.com> | 2024-07-02 12:45:30 -0400 |
|---|---|---|
| committer | David Chase <drchase@google.com> | 2024-07-30 15:02:02 +0000 |
| commit | 4f237ffd16ef1ff11f8fb80083457a47028954ff (patch) | |
| tree | 23ea0dc7e2993225fd0dcd7f55f9570b3e418d32 /src/cmd/compile/internal/rangefunc/rangefunc_test.go | |
| parent | d0a468e52c6f7bc7e3cb4731f03e1693eb535a38 (diff) | |
| download | go-4f237ffd16ef1ff11f8fb80083457a47028954ff.tar.xz | |
cmd/compile: verify that rangefunc assigning to no vars works
This adds a test for
for range seq2rangefunc { ... }
and
for onevar := range seq2rangefunc { ... }
For #65236.
Change-Id: I083f8e4c19eb4ba0d6024d5314ac29d941141778
Reviewed-on: https://go-review.googlesource.com/c/go/+/596135
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Keith Randall <khr@google.com>
Reviewed-by: Keith Randall <khr@golang.org>
Diffstat (limited to 'src/cmd/compile/internal/rangefunc/rangefunc_test.go')
| -rw-r--r-- | src/cmd/compile/internal/rangefunc/rangefunc_test.go | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/src/cmd/compile/internal/rangefunc/rangefunc_test.go b/src/cmd/compile/internal/rangefunc/rangefunc_test.go index 97ab254395..1d0bed05c8 100644 --- a/src/cmd/compile/internal/rangefunc/rangefunc_test.go +++ b/src/cmd/compile/internal/rangefunc/rangefunc_test.go @@ -285,6 +285,26 @@ var fail []error = []error{ errorString(CERR_MISSING), } +// TestNoVars ensures that versions of rangefunc that use zero or one +// iteration variable (instead of two) run the proper number of times +// and in the one variable case supply the proper values. +// For #65236. +func TestNoVars(t *testing.T) { + i, k := 0, 0 + for range Check2(OfSliceIndex([]int{1, 2, 3, 4, 5, 6, 7, 8, 9, 10})) { + i++ + } + for j := range Check2(OfSliceIndex([]int{1, 2, 3, 4, 5, 6, 7, 8, 9, 10})) { + k += j + } + if i != 10 { + t.Errorf("Expected 10, got %d", i) + } + if k != 45 { + t.Errorf("Expected 45, got %d", k) + } +} + func TestCheck(t *testing.T) { i := 0 defer func() { |
