aboutsummaryrefslogtreecommitdiff
path: root/src/go
diff options
context:
space:
mode:
authorRobert Griesemer <gri@golang.org>2024-04-15 14:10:40 -0700
committerRobert Griesemer <gri@google.com>2024-04-16 21:06:56 +0000
commit15cec430d75741960829e7e227c1b7c3e1f79114 (patch)
tree119d074fcee14d2e46c3b2513f97cc7a6d208c92 /src/go
parent661f98141ac8b919802343467c05ea74abf8fae1 (diff)
downloadgo-15cec430d75741960829e7e227c1b7c3e1f79114.tar.gz
go-15cec430d75741960829e7e227c1b7c3e1f79114.zip
types2: flip the default value of GODEBUG=gotypesalias=1
This CL changes the interpretation of the unset value of gotypesalias to not equal "0". This is a port of CL 577715 from go/types to types2, with adjustments to go/types to keep the source code in sync. Specifically: - Re-introduce testing of both modes (gotypesalias=0, gotypesalias=1) in go/types. - Re-introduce setting of gotypesalias in some of the tests for explicit documentation in go/types. The compiler still uses the (now) non-default setting due to a panic with the default setting that needs to be debugged. Also, the type checkers still don't call IncNonDefault when the non-default setting of gotypesalias is used. Change-Id: I1feed3eb334c202950ac5aadf49a74adcce0d8c3 Reviewed-on: https://go-review.googlesource.com/c/go/+/579076 TryBot-Bypass: Robert Griesemer <gri@google.com> Reviewed-by: Robert Griesemer <gri@google.com> Reviewed-by: Alan Donovan <adonovan@google.com> Reviewed-by: Robert Findley <rfindley@google.com> Auto-Submit: Robert Griesemer <gri@google.com>
Diffstat (limited to 'src/go')
-rw-r--r--src/go/types/api_test.go1
-rw-r--r--src/go/types/check.go13
-rw-r--r--src/go/types/check_test.go11
-rw-r--r--src/go/types/issues_test.go2
4 files changed, 17 insertions, 10 deletions
diff --git a/src/go/types/api_test.go b/src/go/types/api_test.go
index 7ab695d365..5bc4e8a61f 100644
--- a/src/go/types/api_test.go
+++ b/src/go/types/api_test.go
@@ -2997,6 +2997,7 @@ func TestTooNew(t *testing.T) {
// This is a regression test for #66704.
func TestUnaliasTooSoonInCycle(t *testing.T) {
+ t.Setenv("GODEBUG", "gotypesalias=1")
const src = `package a
var x T[B] // this appears to cause Unalias to be called on B while still Invalid
diff --git a/src/go/types/check.go b/src/go/types/check.go
index 74849171f2..be990eabfe 100644
--- a/src/go/types/check.go
+++ b/src/go/types/check.go
@@ -24,8 +24,9 @@ var noposn = atPos(nopos)
const debug = false // leave on during development
// gotypesalias controls the use of Alias types.
-// As of Apr 12 2024 it is on by default.
-// It will be removed soon.
+// As of Apr 16 2024 they are used by default.
+// To disable their use, set GODEBUG to gotypesalias=0.
+// This GODEBUG flag will be removed in the near future (tentatively Go 1.24).
var gotypesalias = godebug.New("gotypesalias")
// exprInfo stores information about an untyped expression.
@@ -260,14 +261,8 @@ func NewChecker(conf *Config, fset *token.FileSet, pkg *Package, info *Info) *Ch
//
// (previously, pkg.goVersion was mutated here: go.dev/issue/61212)
- enableAlias := false
- switch gotypesalias.Value() {
- case "", "1":
- enableAlias = true
- }
-
return &Checker{
- enableAlias: enableAlias,
+ enableAlias: gotypesalias.Value() != "0",
conf: conf,
ctxt: conf.Context,
fset: fset,
diff --git a/src/go/types/check_test.go b/src/go/types/check_test.go
index 63891e9056..6ad7ef3a27 100644
--- a/src/go/types/check_test.go
+++ b/src/go/types/check_test.go
@@ -124,6 +124,8 @@ func parseFlags(src []byte, flags *flag.FlagSet) error {
// testFiles type-checks the package consisting of the given files, and
// compares the resulting errors with the ERROR annotations in the source.
+// Except for manual tests, each package is type-checked twice, once without
+// use of Alias types, and once with Alias types.
//
// The srcs slice contains the file content for the files named in the
// filenames slice. The colDelta parameter specifies the tolerance for position
@@ -132,6 +134,15 @@ func parseFlags(src []byte, flags *flag.FlagSet) error {
//
// If provided, opts may be used to mutate the Config before type-checking.
func testFiles(t *testing.T, filenames []string, srcs [][]byte, manual bool, opts ...func(*Config)) {
+ // Alias types are enabled by default
+ testFilesImpl(t, filenames, srcs, manual, opts...)
+ if !manual {
+ t.Setenv("GODEBUG", "gotypesalias=0")
+ testFilesImpl(t, filenames, srcs, manual, opts...)
+ }
+}
+
+func testFilesImpl(t *testing.T, filenames []string, srcs [][]byte, manual bool, opts ...func(*Config)) {
if len(filenames) == 0 {
t.Fatal("no source files")
}
diff --git a/src/go/types/issues_test.go b/src/go/types/issues_test.go
index eb627eaee7..4f4bf6f077 100644
--- a/src/go/types/issues_test.go
+++ b/src/go/types/issues_test.go
@@ -998,7 +998,7 @@ type A = []int
type S struct{ A }
`
- // t.Setenv("GODEBUG", "gotypesalias=1") // now on by default
+ t.Setenv("GODEBUG", "gotypesalias=1")
pkg := mustTypecheck(src, nil, nil)
S := pkg.Scope().Lookup("S")