From: Russ Cox Date: Tue, 23 Jan 2024 17:02:50 +0000 (-0500) Subject: all: enable range-over-func in Go 1.23 X-Git-Tag: go1.23rc1~1373 X-Git-Url: http://www.git.cypherpunks.su/?a=commitdiff_plain;h=d278d5bbdddd0e976c272d1dd3ecc41eeb37daf9;p=gostls13.git 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 LUCI-TryBot-Result: Go LUCI Reviewed-by: Robert Findley --- diff --git a/src/cmd/compile/internal/types2/stmt.go b/src/cmd/compile/internal/types2/stmt.go index c9713dac6f..272636ff39 100644 --- a/src/cmd/compile/internal/types2/stmt.go +++ b/src/cmd/compile/internal/types2/stmt.go @@ -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 { diff --git a/src/cmd/compile/internal/types2/version.go b/src/cmd/compile/internal/types2/version.go index 5aa3c803b5..b904072a7b 100644 --- a/src/cmd/compile/internal/types2/version.go +++ b/src/cmd/compile/internal/types2/version.go @@ -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)) diff --git a/src/go/types/stmt.go b/src/go/types/stmt.go index 80f3ac75da..660085d6f2 100644 --- a/src/go/types/stmt.go +++ b/src/go/types/stmt.go @@ -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 { diff --git a/src/go/types/version.go b/src/go/types/version.go index f2466edc1f..1b02ae5493 100644 --- a/src/go/types/version.go +++ b/src/go/types/version.go @@ -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)) diff --git a/src/internal/types/testdata/spec/range.go b/src/internal/types/testdata/spec/range.go index 4ae270d233..07bd6b6769 100644 --- a/src/internal/types/testdata/spec/range.go +++ b/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.