"fmt"
"internal/buildcfg"
"internal/types/errors"
+ "os"
"regexp"
"sort"
base.ErrorfAt(m.makeXPos(terr.Pos), terr.Code, "%s", msg)
}
+ // Currently, the compiler panics when using Alias types.
+ // Use the non-default setting for now.
+ // TODO(gri) set this to gotypesalias=1 or remove this call.
+ os.Setenv("GODEBUG", "gotypesalias=0")
pkg, err := conf.Check(base.Ctxt.Pkgpath, files, info)
base.ExitIfErrors()
if err != nil {
const debug = false // leave on during development
// gotypesalias controls the use of Alias types.
-var gotypesalias = godebug.New("#gotypesalias")
+// 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.
type exprInfo struct {
// (previously, pkg.goVersion was mutated here: go.dev/issue/61212)
return &Checker{
- enableAlias: gotypesalias.Value() == "1",
+ enableAlias: gotypesalias.Value() != "0",
conf: conf,
ctxt: conf.Context,
pkg: pkg,
//
// If provided, opts may be used to mutate the Config before type-checking.
func testFiles(t *testing.T, filenames []string, srcs [][]byte, colDelta uint, manual bool, opts ...func(*Config)) {
- // Alias types are disabled by default
+ // Alias types are enabled by default
testFilesImpl(t, filenames, srcs, colDelta, manual, opts...)
if !manual {
- t.Setenv("GODEBUG", "gotypesalias=1")
+ t.Setenv("GODEBUG", "gotypesalias=0")
testFilesImpl(t, filenames, srcs, colDelta, manual, opts...)
}
}
Unalias(alias) // resolve alias.actual
} else {
if !versionErr && tparam0 != nil {
- check.error(tdecl, UnsupportedFeature, "generic type alias requires GODEBUG=gotypesalias=1")
+ check.error(tdecl, UnsupportedFeature, "generic type alias requires GODEBUG=gotypesalias=1 or unset")
versionErr = true
}
return n.Underlying().(*Struct).Field(0).Type().(*Pointer).Elem().(*Named)
}
- Inst := pkg.Scope().Lookup("Inst").Type().(*Pointer).Elem().(*Named)
+ Inst := Unalias(pkg.Scope().Lookup("Inst").Type()).(*Pointer).Elem().(*Named)
Node := firstFieldType(Inst)
Tree := firstFieldType(Node)
if !Identical(Inst, Tree) {
// 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
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.
//
// (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,
// 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
//
// 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")
}
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")