Skip to content

Commit ec7d609

Browse files
committed
[release-branch.go1.23] revert "go/types, types2: only use fileVersion if 1.21 or greater"
This reverts commit CL 604935. Reason for revert: The team has decided that this change will be added to a point release. Change-Id: I1c1032b881c3a98312a4753b9767cb7c8eed9e09 Reviewed-on: https://go-review.googlesource.com/c/go/+/605096 LUCI-TryBot-Result: Go LUCI <[email protected]> Reviewed-by: David Chase <[email protected]> Reviewed-by: Michael Matloob <[email protected]>
1 parent 63b0f80 commit ec7d609

File tree

10 files changed

+22
-87
lines changed

10 files changed

+22
-87
lines changed

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

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2903,21 +2903,17 @@ func TestFileVersions(t *testing.T) {
29032903
{"", "go1.20", ""}, // file upgrade ignored
29042904
{"go1.19", "go1.20", "go1.20"}, // file upgrade permitted
29052905
{"go1.20", "go1.19", "go1.20"}, // file downgrade not permitted
2906-
{"go1.21", "go1.20", "go1.21"}, // file downgrade not permitted
2907-
{"go1.22", "go1.21", "go1.21"}, // file downgrade permitted (file and module version are >= go1.21)
2906+
{"go1.21", "go1.19", "go1.19"}, // file downgrade permitted (module version is >= go1.21)
29082907

29092908
// versions containing release numbers
29102909
// (file versions containing release numbers are considered invalid)
29112910
{"go1.19.0", "", "go1.19.0"}, // no file version specified
29122911
{"go1.20", "go1.20.1", "go1.20"}, // file upgrade ignored
29132912
{"go1.20.1", "go1.20", "go1.20.1"}, // file upgrade ignored
2914-
{"go1.21.0", "go1.21.1", "go1.21.0"}, // file upgrade ignored
2915-
{"go1.21", "go1.21.1", "go1.21"}, // file upgrade ignored
29162913
{"go1.20.1", "go1.21", "go1.21"}, // file upgrade permitted
2917-
{"go1.21.1", "go1.21", "go1.21.1"}, // file downgrade ignored
29182914
{"go1.20.1", "go1.19", "go1.20.1"}, // file downgrade not permitted
29192915
{"go1.21.1", "go1.19.1", "go1.21.1"}, // file downgrade not permitted (invalid file version)
2920-
{"go1.22.1", "go1.21", "go1.21"}, // file downgrade permitted (file and module version is >= go1.21)
2916+
{"go1.21.1", "go1.19", "go1.19"}, // file downgrade permitted (module version is >= go1.21)
29212917
} {
29222918
var src string
29232919
if test.fileVersion != "" {

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

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -354,25 +354,12 @@ func (check *Checker) initFiles(files []*syntax.File) {
354354
// To work around this, downgrades are only allowed when the
355355
// module's Go version is Go 1.21 or later.
356356
//
357-
// Downgrades are also only allowed to Go versions Go 1.21 or later.
358-
// In GOPATH mode, there's no way to set a module version and the
359-
// -lang is set to the local toolchain version to allow the use of
360-
// new features in GOPATH mode. But //go:build lines added before go1.21
361-
// weren't intended to downgrade, so code with //go:build lines for
362-
// go versions earlier than 1.21 may use language features added
363-
// in later versions and compile.
364-
//
365-
// We should probably change the downgradeOk condition to capture this
366-
// instead of adding an extra condition, but to make the change simpler,
367-
// we've tried to limit it to one line.
368-
// TODO(gri): simplify this code after 1.23 has shipped
369-
//
370357
// If there is no valid check.version, then we don't really know what
371358
// Go version to apply.
372359
// Legacy tools may do this, and they historically have accepted everything.
373360
// Preserve that behavior by ignoring //go:build constraints entirely in that
374361
// case (!pkgVersionOk).
375-
if cmp > 0 || cmp < 0 && downgradeOk && fileVersion.cmp(go1_21) >= 0 {
362+
if cmp > 0 || cmp < 0 && downgradeOk {
376363
v = file.GoVersion
377364
}
378365
}

src/go/types/api_test.go

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2909,21 +2909,17 @@ func TestFileVersions(t *testing.T) {
29092909
{"", "go1.20", ""}, // file upgrade ignored
29102910
{"go1.19", "go1.20", "go1.20"}, // file upgrade permitted
29112911
{"go1.20", "go1.19", "go1.20"}, // file downgrade not permitted
2912-
{"go1.21", "go1.20", "go1.21"}, // file downgrade not permitted
2913-
{"go1.22", "go1.21", "go1.21"}, // file downgrade permitted (file and module version are >= go1.21)
2912+
{"go1.21", "go1.19", "go1.19"}, // file downgrade permitted (module version is >= go1.21)
29142913

29152914
// versions containing release numbers
29162915
// (file versions containing release numbers are considered invalid)
29172916
{"go1.19.0", "", "go1.19.0"}, // no file version specified
29182917
{"go1.20", "go1.20.1", "go1.20"}, // file upgrade ignored
29192918
{"go1.20.1", "go1.20", "go1.20.1"}, // file upgrade ignored
2920-
{"go1.21.0", "go1.21.1", "go1.21.0"}, // file upgrade ignored
2921-
{"go1.21", "go1.21.1", "go1.21"}, // file upgrade ignored
29222919
{"go1.20.1", "go1.21", "go1.21"}, // file upgrade permitted
2923-
{"go1.21.1", "go1.21", "go1.21.1"}, // file downgrade ignored
29242920
{"go1.20.1", "go1.19", "go1.20.1"}, // file downgrade not permitted
29252921
{"go1.21.1", "go1.19.1", "go1.21.1"}, // file downgrade not permitted (invalid file version)
2926-
{"go1.22.1", "go1.21", "go1.21"}, // file downgrade permitted (file and module version is >= go1.21)
2922+
{"go1.21.1", "go1.19", "go1.19"}, // file downgrade permitted (module version is >= go1.21)
29272923
} {
29282924
var src string
29292925
if test.fileVersion != "" {

src/go/types/check.go

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -376,25 +376,12 @@ func (check *Checker) initFiles(files []*ast.File) {
376376
// To work around this, downgrades are only allowed when the
377377
// module's Go version is Go 1.21 or later.
378378
//
379-
// Downgrades are also only allowed to Go versions Go 1.21 or later.
380-
// In GOPATH mode, there's no way to set a module version and the
381-
// -lang is set to the local toolchain version to allow the use of
382-
// new features in GOPATH mode. But //go:build lines added before go1.21
383-
// weren't intended to downgrade, so code with //go:build lines for
384-
// go versions earlier than 1.21 may use language features added
385-
// in later versions and compile.
386-
//
387-
// We should probably change the downgradeOk condition to capture this
388-
// instead of adding an extra condition, but to make the change simpler,
389-
// we've tried to limit it to one line.
390-
// TODO(gri): simplify this code after 1.23 has shipped
391-
//
392379
// If there is no valid check.version, then we don't really know what
393380
// Go version to apply.
394381
// Legacy tools may do this, and they historically have accepted everything.
395382
// Preserve that behavior by ignoring //go:build constraints entirely in that
396383
// case (!pkgVersionOk).
397-
if cmp > 0 || cmp < 0 && downgradeOk && fileVersion.cmp(go1_21) >= 0 {
384+
if cmp > 0 || cmp < 0 && downgradeOk {
398385
v = file.GoVersion
399386
}
400387
}

src/internal/types/testdata/check/go1_20_19.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,4 @@ type Slice []byte
1414
type Array [8]byte
1515

1616
var s Slice
17-
var p = (Array)(s /* ok because downgrades below 1.21 are ignored */)
17+
var p = (Array)(s /* ok because Go 1.20 ignored the //go:build go1.19 */)

src/internal/types/testdata/check/go1_21_19.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,4 @@ type Slice []byte
1414
type Array [8]byte
1515

1616
var s Slice
17-
var p = (Array)(s /* ok because downgrades below 1.21 are ignored */)
17+
var p = (Array)(s /* ERROR "requires go1.20 or later" */)

src/internal/types/testdata/check/go1_21_22.go

Lines changed: 0 additions & 16 deletions
This file was deleted.

src/internal/types/testdata/check/go1_22_21.go

Lines changed: 0 additions & 16 deletions
This file was deleted.

src/internal/types/testdata/fixedbugs/issue66285.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,14 @@
1-
// -lang=go1.13
1+
// -lang=go1.21
22

33
// Copyright 2024 The Go Authors. All rights reserved.
44
// Use of this source code is governed by a BSD-style
55
// license that can be found in the LICENSE file.
66

7+
// Note: Downgrading to go1.13 requires at least go1.21,
8+
// hence the need for -lang=go1.21 at the top.
9+
10+
//go:build go1.13
11+
712
package p
813

914
import "io"

test/fixedbugs/issue63489a.go

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,16 @@
1-
// errorcheck -lang=go1.22
1+
// errorcheck -lang=go1.21
22

33
// Copyright 2023 The Go Authors. All rights reserved.
44
// Use of this source code is governed by a BSD-style
55
// license that can be found in the LICENSE file.
66

7-
// This file has been changed from its original version as
8-
// //go:build language downgrades below go1.21 are no longer
9-
// supported. The original tested a downgrade from go1.21 to
10-
// go1.4 while this new version tests a downgrade from go1.22
11-
// to go1.21
12-
13-
//go:build go1.21
7+
//go:build go1.4
148

159
package p
1610

17-
func f() {
18-
for _ = range 10 { // ERROR "file declares //go:build go1.21"
19-
}
20-
}
11+
const c = 0o123 // ERROR "file declares //go:build go1.4"
12+
13+
// ERROR "file declares //go:build go1.4"
14+
15+
//line issue63489a.go:13:1
16+
const d = 0o124

0 commit comments

Comments
 (0)