1
0
mirror of https://github.com/golang/go synced 2024-11-17 10:14:46 -07:00

all: enable range-over-func in Go 1.23

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>
This commit is contained in:
Russ Cox 2024-01-23 12:02:50 -05:00
parent 3dcdc09c85
commit d278d5bbdd
5 changed files with 6 additions and 8 deletions

View 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 {

View 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))

View 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 {

View 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))

View 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.