Source File
aliases_go122.go
Belonging Package
golang.org/x/tools/internal/aliases
// Copyright 2024 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.
//go:build go1.22
// +build go1.22
package aliases
import (
)
// Alias is an alias of types.Alias.
type Alias = types.Alias
// Rhs returns the type on the right-hand side of the alias declaration.
func ( *Alias) types.Type {
if , := any().(interface{ () types.Type }); {
return .() // go1.23+
}
// go1.22's Alias didn't have the Rhs method,
// so Unalias is the best we can do.
return Unalias()
}
// Unalias is a wrapper of types.Unalias.
func ( types.Type) types.Type { return types.Unalias() }
// newAlias is an internal alias around types.NewAlias.
// Direct usage is discouraged as the moment.
// Try to use NewAlias instead.
func ( *types.TypeName, types.Type) *Alias {
:= types.NewAlias(, )
// TODO(go.dev/issue/65455): Remove kludgy workaround to set a.actual as a side-effect.
Unalias()
return
}
// Enabled reports whether [NewAlias] should create [types.Alias] types.
//
// This function is expensive! Call it sparingly.
func () bool {
// The only reliable way to compute the answer is to invoke go/types.
// We don't parse the GODEBUG environment variable, because
// (a) it's tricky to do so in a manner that is consistent
// with the godebug package; in particular, a simple
// substring check is not good enough. The value is a
// rightmost-wins list of options. But more importantly:
// (b) it is impossible to detect changes to the effective
// setting caused by os.Setenv("GODEBUG"), as happens in
// many tests. Therefore any attempt to cache the result
// is just incorrect.
:= token.NewFileSet()
, := parser.ParseFile(, "a.go", "package p; type A = int", 0)
, := new(types.Config).Check("p", , []*ast.File{}, nil)
, := .Scope().Lookup("A").Type().(*types.Alias)
return
}
The pages are generated with Golds v0.7.6. (GOOS=linux GOARCH=amd64)