]> Cypherpunks repositories - gostls13.git/commitdiff
all: enable range-over-func in Go 1.23
authorRuss Cox <rsc@golang.org>
Tue, 23 Jan 2024 17:02:50 +0000 (12:02 -0500)
committerRuss Cox <rsc@golang.org>
Fri, 26 Jan 2024 04:31:42 +0000 (04:31 +0000)
GOEXPERIMENT=rangefunc still enables it for all Go modules.
Otherwise only enable in Go 1.23 source files.
More work remains but it will be done in follow-up issues.

Fixes #61405.

Change-Id: Icad64942deb152ee65444e4d7be289814a8a0b6b
Reviewed-on: https://go-review.googlesource.com/c/go/+/557835
Reviewed-by: Robert Griesemer <gri@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Robert Findley <rfindley@google.com>
src/cmd/compile/internal/types2/stmt.go
src/cmd/compile/internal/types2/version.go
src/go/types/stmt.go
src/go/types/version.go
src/internal/types/testdata/spec/range.go

index c9713dac6fe7ff5a387c13b08e30269fc216dafe..272636ff39f8f8fb8d0604046a7da5c16d0c0b8b 100644 (file)
@@ -1026,9 +1026,8 @@ func rangeKeyVal(typ Type, allowVersion func(goVersion) bool) (key, val Type, ca
                }
                return typ.elem, nil, "", false, true
        case *Signature:
-               // TODO(gri) when this becomes enabled permanently, add version check
-               if !buildcfg.Experiment.RangeFunc {
-                       break
+               if !buildcfg.Experiment.RangeFunc && allowVersion != nil && !allowVersion(go1_23) {
+                       return bad("requires go1.23 or later")
                }
                assert(typ.Recv() == nil)
                switch {
index 5aa3c803b54996b345f11c881c28d522b7821956..b904072a7baa8c70eb85c705dacc6be35e6742d5 100644 (file)
@@ -44,6 +44,7 @@ var (
        go1_20 = asGoVersion("go1.20")
        go1_21 = asGoVersion("go1.21")
        go1_22 = asGoVersion("go1.22")
+       go1_23 = asGoVersion("go1.23")
 
        // current (deployed) Go version
        go_current = asGoVersion(fmt.Sprintf("go1.%d", goversion.Version))
index 80f3ac75da2cd8255383015dba6d6c6ff03af8d8..660085d6f2a17d15152d9223738904d2817ab2e7 100644 (file)
@@ -1010,9 +1010,8 @@ func rangeKeyVal(typ Type, allowVersion func(goVersion) bool) (key, val Type, ca
                }
                return typ.elem, nil, "", false, true
        case *Signature:
-               // TODO(gri) when this becomes enabled permanently, add version check
-               if !buildcfg.Experiment.RangeFunc {
-                       break
+               if !buildcfg.Experiment.RangeFunc && allowVersion != nil && !allowVersion(go1_23) {
+                       return bad("requires go1.23 or later")
                }
                assert(typ.Recv() == nil)
                switch {
index f2466edc1fa1cee296d60d64afedd31686fde090..1b02ae54932075812b2b7fb1b6d9abc2cdebf43d 100644 (file)
@@ -45,6 +45,7 @@ var (
        go1_20 = asGoVersion("go1.20")
        go1_21 = asGoVersion("go1.21")
        go1_22 = asGoVersion("go1.22")
+       go1_23 = asGoVersion("go1.23")
 
        // current (deployed) Go version
        go_current = asGoVersion(fmt.Sprintf("go1.%d", goversion.Version))
index 4ae270d233d7b2694f7e6e423b15640300491a90..07bd6b6769b6f7eb4441eda3b137ec208b6820c9 100644 (file)
@@ -1,5 +1,3 @@
-// -goexperiment=rangefunc
-
 // Copyright 2023 The Go Authors. All rights reserved.
 // Use of this source code is governed by a BSD-style
 // license that can be found in the LICENSE file.