Skip to content

Commit d278d5b

Browse files
committed
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 <[email protected]> LUCI-TryBot-Result: Go LUCI <[email protected]> Reviewed-by: Robert Findley <[email protected]>
1 parent 3dcdc09 commit d278d5b

File tree

5 files changed

+6
-8
lines changed

5 files changed

+6
-8
lines changed

src/cmd/compile/internal/types2/stmt.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1026,9 +1026,8 @@ func rangeKeyVal(typ Type, allowVersion func(goVersion) bool) (key, val Type, ca
10261026
}
10271027
return typ.elem, nil, "", false, true
10281028
case *Signature:
1029-
// TODO(gri) when this becomes enabled permanently, add version check
1030-
if !buildcfg.Experiment.RangeFunc {
1031-
break
1029+
if !buildcfg.Experiment.RangeFunc && allowVersion != nil && !allowVersion(go1_23) {
1030+
return bad("requires go1.23 or later")
10321031
}
10331032
assert(typ.Recv() == nil)
10341033
switch {

src/cmd/compile/internal/types2/version.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ var (
4444
go1_20 = asGoVersion("go1.20")
4545
go1_21 = asGoVersion("go1.21")
4646
go1_22 = asGoVersion("go1.22")
47+
go1_23 = asGoVersion("go1.23")
4748

4849
// current (deployed) Go version
4950
go_current = asGoVersion(fmt.Sprintf("go1.%d", goversion.Version))

src/go/types/stmt.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1010,9 +1010,8 @@ func rangeKeyVal(typ Type, allowVersion func(goVersion) bool) (key, val Type, ca
10101010
}
10111011
return typ.elem, nil, "", false, true
10121012
case *Signature:
1013-
// TODO(gri) when this becomes enabled permanently, add version check
1014-
if !buildcfg.Experiment.RangeFunc {
1015-
break
1013+
if !buildcfg.Experiment.RangeFunc && allowVersion != nil && !allowVersion(go1_23) {
1014+
return bad("requires go1.23 or later")
10161015
}
10171016
assert(typ.Recv() == nil)
10181017
switch {

src/go/types/version.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ var (
4545
go1_20 = asGoVersion("go1.20")
4646
go1_21 = asGoVersion("go1.21")
4747
go1_22 = asGoVersion("go1.22")
48+
go1_23 = asGoVersion("go1.23")
4849

4950
// current (deployed) Go version
5051
go_current = asGoVersion(fmt.Sprintf("go1.%d", goversion.Version))

src/internal/types/testdata/spec/range.go

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
// -goexperiment=rangefunc
2-
31
// Copyright 2023 The Go Authors. All rights reserved.
42
// Use of this source code is governed by a BSD-style
53
// license that can be found in the LICENSE file.

0 commit comments

Comments
 (0)