Skip to content

Commit

Permalink
all: enable range-over-func in Go 1.23
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
rsc authored and pull[bot] committed Apr 8, 2024
1 parent d210b34 commit 3595248
Show file tree
Hide file tree
Showing 5 changed files with 6 additions and 8 deletions.
5 changes: 2 additions & 3 deletions src/cmd/compile/internal/types2/stmt.go
Expand Up @@ -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 {
Expand Down
1 change: 1 addition & 0 deletions src/cmd/compile/internal/types2/version.go
Expand Up @@ -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))
Expand Down
5 changes: 2 additions & 3 deletions src/go/types/stmt.go
Expand Up @@ -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 {
Expand Down
1 change: 1 addition & 0 deletions src/go/types/version.go
Expand Up @@ -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))
Expand Down
2 changes: 0 additions & 2 deletions src/internal/types/testdata/spec/range.go
@@ -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.
Expand Down

0 comments on commit 3595248

Please sign in to comment.