internal/aliases: remove Alias and Unalias

These two declarations can now safely be accessed directly
from go/types.

Also, remove all mention of internal/aliases from gopls/...
We can enable two suppressed tests now that go1.23 is assured.

Updates golang/go#46477

Change-Id: I9ae8536b0d022e3300b285547c18202bed302cf2
Reviewed-on: https://go-review.googlesource.com/c/tools/+/614638
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Commit-Queue: Tim King <taking@google.com>
Reviewed-by: Tim King <taking@google.com>
This commit is contained in:
Alan Donovan 2024-09-20 14:52:41 -04:00
Родитель 0b6abe39e0
Коммит 1d5e334177
78 изменённых файлов: 168 добавлений и 321 удалений

Просмотреть файл

@ -12,8 +12,6 @@ import (
"go/types"
"io"
"math/big"
"golang.org/x/tools/internal/aliases"
)
// TODO(gri) use tabwriter for alignment?
@ -58,7 +56,7 @@ func (p *printer) printf(format string, args ...interface{}) {
// denoted by obj is not an interface and has methods. Otherwise it returns
// the zero value.
func methodsFor(obj *types.TypeName) (*types.Named, []*types.Selection) {
named, _ := aliases.Unalias(obj.Type()).(*types.Named)
named, _ := types.Unalias(obj.Type()).(*types.Named)
if named == nil {
// A type name's type can also be the
// exported basic type unsafe.Pointer.

Просмотреть файл

@ -14,8 +14,6 @@ package main
import (
"go/types"
"golang.org/x/tools/internal/aliases"
)
func (p *printer) writeType(this *types.Package, typ types.Type) {
@ -177,9 +175,9 @@ func (p *printer) writeTypeInternal(this *types.Package, typ types.Type, visited
p.print(")")
}
case *aliases.Alias:
case *types.Alias:
// TODO(adonovan): display something aliasy.
p.writeTypeInternal(this, aliases.Unalias(t), visited)
p.writeTypeInternal(this, types.Unalias(t), visited)
case *types.Named:
s := "<Named w/o object>"

Просмотреть файл

@ -15,7 +15,6 @@ import (
"golang.org/x/tools/go/analysis"
"golang.org/x/tools/go/analysis/passes/inspect"
"golang.org/x/tools/go/ast/inspector"
"golang.org/x/tools/internal/aliases"
"golang.org/x/tools/internal/typeparams"
)
@ -72,7 +71,7 @@ func run(pass *analysis.Pass) (interface{}, error) {
return
}
var structuralTypes []types.Type
switch typ := aliases.Unalias(typ).(type) {
switch typ := types.Unalias(typ).(type) {
case *types.TypeParam:
terms, err := typeparams.StructuralTerms(typ)
if err != nil {
@ -146,7 +145,7 @@ func run(pass *analysis.Pass) (interface{}, error) {
// isLocalType reports whether typ belongs to the same package as pass.
// TODO(adonovan): local means "internal to a function"; rename to isSamePackageType.
func isLocalType(pass *analysis.Pass, typ types.Type) bool {
switch x := aliases.Unalias(typ).(type) {
switch x := types.Unalias(typ).(type) {
case *types.Struct:
// struct literals are local types
return true

Просмотреть файл

@ -17,7 +17,6 @@ import (
"golang.org/x/tools/go/analysis/passes/inspect"
"golang.org/x/tools/go/analysis/passes/internal/analysisutil"
"golang.org/x/tools/go/ast/inspector"
"golang.org/x/tools/internal/aliases"
"golang.org/x/tools/internal/typeparams"
"golang.org/x/tools/internal/versions"
)
@ -286,7 +285,7 @@ func lockPath(tpkg *types.Package, typ types.Type, seen map[types.Type]bool) typ
}
seen[typ] = true
if tpar, ok := aliases.Unalias(typ).(*types.TypeParam); ok {
if tpar, ok := types.Unalias(typ).(*types.TypeParam); ok {
terms, err := typeparams.StructuralTerms(tpar)
if err != nil {
return nil // invalid type

Просмотреть файл

@ -15,7 +15,6 @@ import (
"golang.org/x/tools/go/analysis/passes/internal/analysisutil"
"golang.org/x/tools/go/ast/inspector"
"golang.org/x/tools/go/types/typeutil"
"golang.org/x/tools/internal/aliases"
)
const Doc = `check for calls of reflect.DeepEqual on error values
@ -102,7 +101,7 @@ func containsError(typ types.Type) bool {
return true
}
}
case *types.Named, *aliases.Alias:
case *types.Named, *types.Alias:
return check(t.Underlying())
// We list the remaining valid type kinds for completeness.

Просмотреть файл

@ -14,7 +14,6 @@ import (
"golang.org/x/tools/go/analysis/passes/inspect"
"golang.org/x/tools/go/analysis/passes/internal/analysisutil"
"golang.org/x/tools/go/ast/inspector"
"golang.org/x/tools/internal/aliases"
"golang.org/x/tools/internal/typesinternal"
)
@ -137,7 +136,7 @@ func isHTTPFuncOrMethodOnClient(info *types.Info, expr *ast.CallExpr) bool {
if analysisutil.IsNamedType(typ, "net/http", "Client") {
return true // method on http.Client.
}
ptr, ok := aliases.Unalias(typ).(*types.Pointer)
ptr, ok := types.Unalias(typ).(*types.Pointer)
return ok && analysisutil.IsNamedType(ptr.Elem(), "net/http", "Client") // method on *http.Client.
}

Просмотреть файл

@ -15,7 +15,6 @@ import (
"os"
"golang.org/x/tools/go/analysis"
"golang.org/x/tools/internal/aliases"
"golang.org/x/tools/internal/analysisinternal"
)
@ -121,7 +120,7 @@ func Imports(pkg *types.Package, path string) bool {
// This function avoids allocating the concatenation of "pkg.Name",
// which is important for the performance of syntax matching.
func IsNamedType(t types.Type, pkgPath string, names ...string) bool {
n, ok := aliases.Unalias(t).(*types.Named)
n, ok := types.Unalias(t).(*types.Named)
if !ok {
return false
}

Просмотреть файл

@ -14,7 +14,6 @@ import (
"golang.org/x/tools/go/analysis/passes/buildssa"
"golang.org/x/tools/go/analysis/passes/internal/analysisutil"
"golang.org/x/tools/go/ssa"
"golang.org/x/tools/internal/aliases"
"golang.org/x/tools/internal/typeparams"
)
@ -300,7 +299,7 @@ func nilnessOf(stack []fact, v ssa.Value) nilness {
}
case *ssa.MakeInterface:
// A MakeInterface is non-nil unless its operand is a type parameter.
tparam, ok := aliases.Unalias(v.X.Type()).(*types.TypeParam)
tparam, ok := types.Unalias(v.X.Type()).(*types.TypeParam)
if !ok {
return isnonnil
}

Просмотреть файл

@ -24,7 +24,6 @@ import (
"golang.org/x/tools/go/analysis/passes/internal/analysisutil"
"golang.org/x/tools/go/ast/inspector"
"golang.org/x/tools/go/types/typeutil"
"golang.org/x/tools/internal/aliases"
"golang.org/x/tools/internal/typeparams"
)
@ -161,7 +160,7 @@ func maybePrintfWrapper(info *types.Info, decl ast.Decl) *printfWrapper {
// Check final parameter is "args ...interface{}".
args := params.At(nparams - 1)
iface, ok := aliases.Unalias(args.Type().(*types.Slice).Elem()).(*types.Interface)
iface, ok := types.Unalias(args.Type().(*types.Slice).Elem()).(*types.Interface)
if !ok || !iface.Empty() {
return nil
}
@ -1013,7 +1012,7 @@ func checkPrint(pass *analysis.Pass, call *ast.CallExpr, fn *types.Func) {
typ := params.At(firstArg).Type()
typ = typ.(*types.Slice).Elem()
it, ok := aliases.Unalias(typ).(*types.Interface)
it, ok := types.Unalias(typ).(*types.Interface)
if !ok || !it.Empty() {
// Skip variadic functions accepting non-interface{} args.
return

Просмотреть файл

@ -10,7 +10,6 @@ import (
"go/types"
"golang.org/x/tools/go/analysis"
"golang.org/x/tools/internal/aliases"
"golang.org/x/tools/internal/typeparams"
)
@ -73,7 +72,7 @@ func (m *argMatcher) match(typ types.Type, topLevel bool) bool {
return true
}
if typ, _ := aliases.Unalias(typ).(*types.TypeParam); typ != nil {
if typ, _ := types.Unalias(typ).(*types.TypeParam); typ != nil {
// Avoid infinite recursion through type parameters.
if m.seen[typ] {
return true
@ -276,7 +275,7 @@ func (m *argMatcher) match(typ types.Type, topLevel bool) bool {
}
func isConvertibleToString(typ types.Type) bool {
if bt, ok := aliases.Unalias(typ).(*types.Basic); ok && bt.Kind() == types.UntypedNil {
if bt, ok := types.Unalias(typ).(*types.Basic); ok && bt.Kind() == types.UntypedNil {
// We explicitly don't want untyped nil, which is
// convertible to both of the interfaces below, as it
// would just panic anyway.

Просмотреть файл

@ -21,7 +21,6 @@ import (
"golang.org/x/tools/go/analysis/passes/inspect"
"golang.org/x/tools/go/analysis/passes/internal/analysisutil"
"golang.org/x/tools/go/ast/inspector"
"golang.org/x/tools/internal/aliases"
"golang.org/x/tools/internal/typeparams"
)
@ -100,7 +99,7 @@ func checkLongShift(pass *analysis.Pass, node ast.Node, x, y ast.Expr) {
return
}
var structuralTypes []types.Type
switch t := aliases.Unalias(t).(type) {
switch t := types.Unalias(t).(type) {
case *types.TypeParam:
terms, err := typeparams.StructuralTerms(t)
if err != nil {

Просмотреть файл

@ -15,7 +15,6 @@ import (
"golang.org/x/tools/go/analysis/passes/inspect"
"golang.org/x/tools/go/analysis/passes/internal/analysisutil"
"golang.org/x/tools/go/ast/inspector"
"golang.org/x/tools/internal/aliases"
"golang.org/x/tools/internal/analysisinternal"
"golang.org/x/tools/internal/typeparams"
)
@ -248,7 +247,7 @@ func run(pass *analysis.Pass) (interface{}, error) {
func structuralTypes(t types.Type) ([]types.Type, error) {
var structuralTypes []types.Type
if tp, ok := aliases.Unalias(t).(*types.TypeParam); ok {
if tp, ok := types.Unalias(t).(*types.TypeParam); ok {
terms, err := typeparams.StructuralTerms(tp)
if err != nil {
return nil, err

Просмотреть файл

@ -16,7 +16,6 @@ import (
"golang.org/x/tools/go/analysis/passes/internal/analysisutil"
"golang.org/x/tools/go/ast/inspector"
"golang.org/x/tools/go/types/typeutil"
"golang.org/x/tools/internal/aliases"
)
//go:embed doc.go
@ -270,7 +269,7 @@ func forbiddenMethod(info *types.Info, call *ast.CallExpr) (*types.Var, *types.S
func formatMethod(sel *types.Selection, fn *types.Func) string {
var ptr string
rtype := sel.Recv()
if p, ok := aliases.Unalias(rtype).(*types.Pointer); ok {
if p, ok := types.Unalias(rtype).(*types.Pointer); ok {
ptr = "*"
rtype = p.Elem()
}

Просмотреть файл

@ -16,7 +16,6 @@ import (
"golang.org/x/tools/go/analysis/passes/inspect"
"golang.org/x/tools/go/analysis/passes/internal/analysisutil"
"golang.org/x/tools/go/ast/inspector"
"golang.org/x/tools/internal/aliases"
)
//go:embed doc.go
@ -88,7 +87,7 @@ func isSafeUintptr(info *types.Info, x ast.Expr) bool {
// by the time we get to the conversion at the end.
// For now approximate by saying that *Header is okay
// but Header is not.
pt, ok := aliases.Unalias(info.Types[x.X].Type).(*types.Pointer)
pt, ok := types.Unalias(info.Types[x.X].Type).(*types.Pointer)
if ok && isReflectHeader(pt.Elem()) {
return true
}

Просмотреть файл

@ -12,7 +12,6 @@ import (
"golang.org/x/tools/go/analysis/passes/buildssa"
"golang.org/x/tools/go/analysis/passes/internal/analysisutil"
"golang.org/x/tools/go/ssa"
"golang.org/x/tools/internal/aliases"
"golang.org/x/tools/internal/typeparams"
)
@ -142,7 +141,7 @@ func hasStructOrArrayType(v ssa.Value) bool {
// func (t T) f() { ...}
// the receiver object is of type *T:
// t0 = local T (t) *T
if tp, ok := aliases.Unalias(alloc.Type()).(*types.Pointer); ok {
if tp, ok := types.Unalias(alloc.Type()).(*types.Pointer); ok {
return isStructOrArray(tp.Elem())
}
return false

Просмотреть файл

@ -45,7 +45,6 @@ import (
"golang.org/x/tools/go/callgraph"
"golang.org/x/tools/go/ssa"
"golang.org/x/tools/go/types/typeutil"
"golang.org/x/tools/internal/aliases"
)
// A Result holds the results of Rapid Type Analysis, which includes the
@ -374,7 +373,7 @@ func (r *rta) interfaces(C types.Type) []*types.Interface {
// and update the 'implements' relation.
r.interfaceTypes.Iterate(func(I types.Type, v interface{}) {
iinfo := v.(*interfaceTypeInfo)
if I := aliases.Unalias(I).(*types.Interface); implements(cinfo, iinfo) {
if I := types.Unalias(I).(*types.Interface); implements(cinfo, iinfo) {
iinfo.implementations = append(iinfo.implementations, C)
cinfo.implements = append(cinfo.implements, I)
}
@ -417,7 +416,7 @@ func (r *rta) implementations(I *types.Interface) []types.Type {
// Adapted from needMethods in go/ssa/builder.go
func (r *rta) addRuntimeType(T types.Type, skip bool) {
// Never record aliases.
T = aliases.Unalias(T)
T = types.Unalias(T)
if prev, ok := r.result.RuntimeTypes.At(T).(bool); ok {
if skip && !prev {
@ -456,11 +455,11 @@ func (r *rta) addRuntimeType(T types.Type, skip bool) {
// Each package maintains its own set of types it has visited.
var n *types.Named
switch T := aliases.Unalias(T).(type) {
switch T := types.Unalias(T).(type) {
case *types.Named:
n = T
case *types.Pointer:
n, _ = aliases.Unalias(T.Elem()).(*types.Named)
n, _ = types.Unalias(T.Elem()).(*types.Named)
}
if n != nil {
owner := n.Obj().Pkg()
@ -479,7 +478,7 @@ func (r *rta) addRuntimeType(T types.Type, skip bool) {
}
switch t := T.(type) {
case *aliases.Alias:
case *types.Alias:
panic("unreachable")
case *types.Basic:

Просмотреть файл

@ -22,7 +22,6 @@ import (
"golang.org/x/tools/go/packages"
"golang.org/x/tools/go/ssa"
"golang.org/x/tools/go/ssa/ssautil"
"golang.org/x/tools/internal/aliases"
"golang.org/x/tools/internal/testenv"
"golang.org/x/tools/internal/testfiles"
"golang.org/x/tools/txtar"
@ -257,7 +256,7 @@ func check(t *testing.T, f *ast.File, pkg *ssa.Package, res *rta.Result) {
got := make(stringset)
res.RuntimeTypes.Iterate(func(key types.Type, value interface{}) {
if !value.(bool) { // accessible to reflection
typ := types.TypeString(aliases.Unalias(key), types.RelativeTo(pkg.Pkg))
typ := types.TypeString(types.Unalias(key), types.RelativeTo(pkg.Pkg))
got[typ] = true
}
})

Просмотреть файл

@ -11,7 +11,6 @@ import (
"golang.org/x/tools/go/ssa"
"golang.org/x/tools/go/types/typeutil"
"golang.org/x/tools/internal/aliases"
"golang.org/x/tools/internal/typeparams"
)
@ -676,7 +675,7 @@ func (b *builder) multiconvert(c *ssa.MultiConvert) {
// This is a adaptation of x/exp/typeparams.NormalTerms which x/tools cannot depend on.
var terms []*types.Term
var err error
switch typ := aliases.Unalias(typ).(type) {
switch typ := types.Unalias(typ).(type) {
case *types.TypeParam:
terms, err = typeparams.StructuralTerms(typ)
case *types.Union:
@ -745,7 +744,7 @@ func (b *builder) addInFlowEdge(s, d node) {
// Creates const, pointer, global, func, and local nodes based on register instructions.
func (b *builder) nodeFromVal(val ssa.Value) node {
if p, ok := aliases.Unalias(val.Type()).(*types.Pointer); ok && !types.IsInterface(p.Elem()) && !isFunction(p.Elem()) {
if p, ok := types.Unalias(val.Type()).(*types.Pointer); ok && !types.IsInterface(p.Elem()) && !isFunction(p.Elem()) {
// Nested pointer to interfaces are modeled as a special
// nestedPtrInterface node.
if i := interfaceUnderPtr(p.Elem()); i != nil {

Просмотреть файл

@ -15,7 +15,6 @@ import (
"golang.org/x/tools/go/callgraph/cha"
"golang.org/x/tools/go/ssa"
"golang.org/x/tools/go/ssa/ssautil"
"golang.org/x/tools/internal/aliases"
)
func TestNodeInterface(t *testing.T) {
@ -38,7 +37,7 @@ func TestNodeInterface(t *testing.T) {
reg := firstRegInstr(main) // t0 := *gl
X := pkg.Type("X").Type()
gl := pkg.Var("gl")
glPtrType, ok := aliases.Unalias(gl.Type()).(*types.Pointer)
glPtrType, ok := types.Unalias(gl.Type()).(*types.Pointer)
if !ok {
t.Fatalf("could not cast gl variable to pointer type")
}

Просмотреть файл

@ -8,7 +8,6 @@ import (
"go/types"
"golang.org/x/tools/go/ssa"
"golang.org/x/tools/internal/aliases"
"golang.org/x/tools/internal/typeparams"
)
@ -24,7 +23,7 @@ func isReferenceNode(n node) bool {
return true
}
if _, ok := aliases.Unalias(n.Type()).(*types.Pointer); ok {
if _, ok := types.Unalias(n.Type()).(*types.Pointer); ok {
return true
}
@ -162,7 +161,7 @@ func siteCallees(c ssa.CallInstruction, callees calleesFunc) func(yield func(*ss
}
func canHaveMethods(t types.Type) bool {
t = aliases.Unalias(t)
t = types.Unalias(t)
if _, ok := t.(*types.Named); ok {
return true
}

Просмотреть файл

@ -21,7 +21,6 @@ import (
"text/scanner"
"unicode/utf8"
"golang.org/x/tools/internal/aliases"
"golang.org/x/tools/internal/typesinternal"
)
@ -256,7 +255,7 @@ func (p *parser) parseField(pkg *types.Package) (field *types.Var, tag string) {
if aname, ok := p.aliases[n]; ok {
name = aname
} else {
switch typ := aliases.Unalias(typesinternal.Unpointer(typ)).(type) {
switch typ := types.Unalias(typesinternal.Unpointer(typ)).(type) {
case *types.Basic:
name = typ.Name()
case *types.Named:
@ -575,7 +574,7 @@ func (p *parser) parseNamedType(nlist []interface{}) types.Type {
t := obj.Type()
p.update(t, nlist)
nt, ok := aliases.Unalias(t).(*types.Named)
nt, ok := types.Unalias(t).(*types.Named)
if !ok {
// This can happen for unsafe.Pointer, which is a TypeName holding a Basic type.
pt := p.parseType(pkg)
@ -1330,7 +1329,7 @@ func (p *parser) parsePackage() *types.Package {
}
p.fixups = nil
for _, typ := range p.typeList {
if it, ok := aliases.Unalias(typ).(*types.Interface); ok {
if it, ok := types.Unalias(typ).(*types.Interface); ok {
it.Complete()
}
}

Просмотреть файл

@ -82,7 +82,6 @@ import (
"runtime"
"sync"
"golang.org/x/tools/internal/aliases"
"golang.org/x/tools/internal/typeparams"
"golang.org/x/tools/internal/versions"
)
@ -854,7 +853,7 @@ func (b *builder) expr0(fn *Function, e ast.Expr, tv types.TypeAndValue) Value {
if types.IsInterface(rt) {
// If v may be an interface type I (after instantiating),
// we must emit a check that v is non-nil.
if recv, ok := aliases.Unalias(sel.recv).(*types.TypeParam); ok {
if recv, ok := types.Unalias(sel.recv).(*types.TypeParam); ok {
// Emit a nil check if any possible instantiation of the
// type parameter is an interface type.
if typeSetOf(recv).Len() > 0 {

Просмотреть файл

@ -29,7 +29,6 @@ import (
"golang.org/x/tools/go/loader"
"golang.org/x/tools/go/ssa"
"golang.org/x/tools/go/ssa/ssautil"
"golang.org/x/tools/internal/aliases"
"golang.org/x/tools/internal/testenv"
)
@ -989,7 +988,7 @@ func TestIssue58491Rec(t *testing.T) {
// Find the local type result instantiated with int.
var found bool
for _, rt := range p.Prog.RuntimeTypes() {
if n, ok := aliases.Unalias(rt).(*types.Named); ok {
if n, ok := types.Unalias(rt).(*types.Named); ok {
if u, ok := n.Underlying().(*types.Struct); ok {
found = true
if got, want := n.String(), "p.result"; got != want {

Просмотреть файл

@ -14,7 +14,6 @@ import (
"strconv"
"strings"
"golang.org/x/tools/internal/aliases"
"golang.org/x/tools/internal/typeparams"
)
@ -114,7 +113,7 @@ func zeroString(t types.Type, from *types.Package) string {
}
case *types.Pointer, *types.Slice, *types.Interface, *types.Chan, *types.Map, *types.Signature:
return "nil"
case *types.Named, *aliases.Alias:
case *types.Named, *types.Alias:
return zeroString(t.Underlying(), from)
case *types.Array, *types.Struct:
return relType(t, from) + "{}"

Просмотреть файл

@ -7,7 +7,6 @@ package ssa
import (
"go/types"
"golang.org/x/tools/internal/aliases"
"golang.org/x/tools/internal/typeparams"
)
@ -51,7 +50,7 @@ func typeSetOf(typ types.Type) termList {
var terms []*types.Term
var err error
// typeSetOf(t) == typeSetOf(Unalias(t))
switch typ := aliases.Unalias(typ).(type) {
switch typ := types.Unalias(typ).(type) {
case *types.TypeParam:
terms, err = typeparams.StructuralTerms(typ)
case *types.Union:

Просмотреть файл

@ -17,7 +17,6 @@ import (
"unsafe"
"golang.org/x/tools/go/ssa"
"golang.org/x/tools/internal/aliases"
"golang.org/x/tools/internal/typeparams"
)
@ -236,8 +235,8 @@ func zero(t types.Type) value {
return a
case *types.Named:
return zero(t.Underlying())
case *aliases.Alias:
return zero(aliases.Unalias(t))
case *types.Alias:
return zero(types.Unalias(t))
case *types.Interface:
return iface{} // nil type, methodset and value
case *types.Slice:

Просмотреть файл

@ -18,7 +18,6 @@ import (
"unsafe"
"golang.org/x/tools/go/ssa"
"golang.org/x/tools/internal/aliases"
)
type opaqueType struct {
@ -180,7 +179,7 @@ func ext۰reflect۰Zero(fr *frame, args []value) value {
func reflectKind(t types.Type) reflect.Kind {
switch t := t.(type) {
case *types.Named, *aliases.Alias:
case *types.Named, *types.Alias:
return reflectKind(t.Underlying())
case *types.Basic:
switch t.Kind() {

Просмотреть файл

@ -46,7 +46,6 @@ import (
"golang.org/x/tools/go/ssa"
"golang.org/x/tools/go/types/typeutil"
"golang.org/x/tools/internal/aliases"
)
type value interface{}
@ -119,7 +118,7 @@ func usesBuiltinMap(t types.Type) bool {
switch t := t.(type) {
case *types.Basic, *types.Chan, *types.Pointer:
return true
case *types.Named, *aliases.Alias:
case *types.Named, *types.Alias:
return usesBuiltinMap(t.Underlying())
case *types.Interface, *types.Array, *types.Struct:
return false

Просмотреть файл

@ -144,7 +144,7 @@ func (subst *subster) typ(t types.Type) (res types.Type) {
case *types.Interface:
return subst.interface_(t)
case *aliases.Alias:
case *types.Alias:
return subst.alias(t)
case *types.Named:
@ -317,7 +317,7 @@ func (subst *subster) interface_(iface *types.Interface) *types.Interface {
return types.NewInterfaceType(methods, embeds).Complete()
}
func (subst *subster) alias(t *aliases.Alias) types.Type {
func (subst *subster) alias(t *types.Alias) types.Type {
// See subster.named. This follows the same strategy.
tparams := aliases.TypeParams(t)
targs := aliases.TypeArgs(t)
@ -633,7 +633,7 @@ func reaches(t types.Type, c map[types.Type]bool) (res bool) {
return true
}
}
case *types.Named, *aliases.Alias:
case *types.Named, *types.Alias:
return reaches(t.Underlying(), c)
default:
panic("unreachable")

Просмотреть файл

@ -16,7 +16,6 @@ import (
"sync"
"golang.org/x/tools/go/types/typeutil"
"golang.org/x/tools/internal/aliases"
"golang.org/x/tools/internal/typeparams"
"golang.org/x/tools/internal/typesinternal"
)
@ -287,7 +286,7 @@ func (c *canonizer) List(ts []types.Type) *typeList {
// Is there some top level alias?
var found bool
for _, t := range ts {
if _, ok := t.(*aliases.Alias); ok {
if _, ok := t.(*types.Alias); ok {
found = true
break
}
@ -298,7 +297,7 @@ func (c *canonizer) List(ts []types.Type) *typeList {
cp := make([]types.Type, len(ts)) // copy with top level aliases removed.
for i, t := range ts {
cp[i] = aliases.Unalias(t)
cp[i] = types.Unalias(t)
}
return cp
}
@ -315,7 +314,7 @@ func (c *canonizer) List(ts []types.Type) *typeList {
// For performance, reasons the canonical instance is order-dependent,
// and may contain deeply nested aliases.
func (c *canonizer) Type(T types.Type) types.Type {
T = aliases.Unalias(T) // remove the top level alias.
T = types.Unalias(T) // remove the top level alias.
c.mu.Lock()
defer c.mu.Unlock()
@ -395,10 +394,10 @@ func (m *typeListMap) hash(ts []types.Type) uint32 {
// instantiateMethod instantiates m with targs and returns a canonical representative for this method.
func (canon *canonizer) instantiateMethod(m *types.Func, targs []types.Type, ctxt *types.Context) *types.Func {
recv := recvType(m)
if p, ok := aliases.Unalias(recv).(*types.Pointer); ok {
if p, ok := types.Unalias(recv).(*types.Pointer); ok {
recv = p.Elem()
}
named := aliases.Unalias(recv).(*types.Named)
named := types.Unalias(recv).(*types.Named)
inst, err := types.Instantiate(ctxt, named.Origin(), targs, false)
if err != nil {
panic(err)

Просмотреть файл

@ -30,7 +30,6 @@ import (
"golang.org/x/tools/go/ast/astutil"
"golang.org/x/tools/go/packages"
"golang.org/x/tools/go/types/typeutil"
"golang.org/x/tools/internal/aliases"
"golang.org/x/tools/internal/typeparams"
)
@ -284,7 +283,7 @@ func formatObj(out *strings.Builder, fset *token.FileSet, ref string, obj types.
if obj.IsAlias() {
kind = "type alias"
}
if named, ok := aliases.Unalias(obj.Type()).(*types.Named); ok {
if named, ok := types.Unalias(obj.Type()).(*types.Named); ok {
origin = named.Obj()
}
}

Просмотреть файл

@ -228,7 +228,7 @@ func (enc *Encoder) For(obj types.Object) (Path, error) {
// Reject obviously non-viable cases.
switch obj := obj.(type) {
case *types.TypeName:
if _, ok := aliases.Unalias(obj.Type()).(*types.TypeParam); !ok {
if _, ok := types.Unalias(obj.Type()).(*types.TypeParam); !ok {
// With the exception of type parameters, only package-level type names
// have a path.
return "", fmt.Errorf("no path for %v", obj)
@ -280,7 +280,7 @@ func (enc *Encoder) For(obj types.Object) (Path, error) {
path = append(path, opType)
T := o.Type()
if alias, ok := T.(*aliases.Alias); ok {
if alias, ok := T.(*types.Alias); ok {
if r := findTypeParam(obj, aliases.TypeParams(alias), path, opTypeParam, nil); r != nil {
return Path(r), nil
}
@ -320,7 +320,7 @@ func (enc *Encoder) For(obj types.Object) (Path, error) {
}
// Inspect declared methods of defined types.
if T, ok := aliases.Unalias(o.Type()).(*types.Named); ok {
if T, ok := types.Unalias(o.Type()).(*types.Named); ok {
path = append(path, opType)
// The method index here is always with respect
// to the underlying go/types data structures,
@ -449,8 +449,8 @@ func (enc *Encoder) concreteMethod(meth *types.Func) (Path, bool) {
// nil, it will be allocated as necessary.
func find(obj types.Object, T types.Type, path []byte, seen map[*types.TypeName]bool) []byte {
switch T := T.(type) {
case *aliases.Alias:
return find(obj, aliases.Unalias(T), path, seen)
case *types.Alias:
return find(obj, types.Unalias(T), path, seen)
case *types.Basic, *types.Named:
// Named types belonging to pkg were handled already,
// so T must belong to another package. No path.
@ -626,7 +626,7 @@ func Object(pkg *types.Package, p Path) (types.Object, error) {
// Inv: t != nil, obj == nil
t = aliases.Unalias(t)
t = types.Unalias(t)
switch code {
case opElem:
hasElem, ok := t.(hasElem) // Pointer, Slice, Array, Chan, Map
@ -664,7 +664,7 @@ func Object(pkg *types.Package, p Path) (types.Object, error) {
t = named.Underlying()
case opRhs:
if alias, ok := t.(*aliases.Alias); ok {
if alias, ok := t.(*types.Alias); ok {
t = aliases.Rhs(alias)
} else if false && aliases.Enabled() {
// The Enabled check is too expensive, so for now we

Просмотреть файл

@ -12,7 +12,6 @@ import (
"go/types"
"reflect"
"golang.org/x/tools/internal/aliases"
"golang.org/x/tools/internal/typeparams"
)
@ -260,8 +259,8 @@ func (h Hasher) hashFor(t types.Type) uint32 {
case *types.Basic:
return uint32(t.Kind())
case *aliases.Alias:
return h.Hash(aliases.Unalias(t))
case *types.Alias:
return h.Hash(types.Unalias(t))
case *types.Array:
return 9043 + 2*uint32(t.Len()) + 3*h.Hash(t.Elem())
@ -461,8 +460,8 @@ func (h Hasher) shallowHash(t types.Type) uint32 {
// elements (mostly Slice, Pointer, Basic, Named),
// so there's no need to optimize anything else.
switch t := t.(type) {
case *aliases.Alias:
return h.shallowHash(aliases.Unalias(t))
case *types.Alias:
return h.shallowHash(types.Unalias(t))
case *types.Signature:
var hash uint32 = 604171

Просмотреть файл

@ -9,8 +9,6 @@ package typeutil
import (
"go/types"
"sync"
"golang.org/x/tools/internal/aliases"
)
// A MethodSetCache records the method set of each type T for which
@ -34,12 +32,12 @@ func (cache *MethodSetCache) MethodSet(T types.Type) *types.MethodSet {
cache.mu.Lock()
defer cache.mu.Unlock()
switch T := aliases.Unalias(T).(type) {
switch T := types.Unalias(T).(type) {
case *types.Named:
return cache.lookupNamed(T).value
case *types.Pointer:
if N, ok := aliases.Unalias(T.Elem()).(*types.Named); ok {
if N, ok := types.Unalias(T.Elem()).(*types.Named); ok {
return cache.lookupNamed(N).pointer
}
}

Просмотреть файл

@ -8,8 +8,6 @@ package typeutil
import (
"go/types"
"golang.org/x/tools/internal/aliases"
)
// IntuitiveMethodSet returns the intuitive method set of a type T,
@ -28,7 +26,7 @@ import (
// The order of the result is as for types.MethodSet(T).
func IntuitiveMethodSet(T types.Type, msets *MethodSetCache) []*types.Selection {
isPointerToConcrete := func(T types.Type) bool {
ptr, ok := aliases.Unalias(T).(*types.Pointer)
ptr, ok := types.Unalias(T).(*types.Pointer)
return ok && !types.IsInterface(ptr.Elem())
}

Просмотреть файл

@ -9,6 +9,7 @@ require (
github.com/jba/templatecheck v0.7.0
golang.org/x/mod v0.21.0
golang.org/x/sync v0.8.0
golang.org/x/sys v0.25.0
golang.org/x/telemetry v0.0.0-20240829154258-f29ab539cc98
golang.org/x/text v0.18.0
golang.org/x/tools v0.21.1-0.20240508182429-e35e4ccd0d2d
@ -23,7 +24,6 @@ require (
github.com/BurntSushi/toml v1.2.1 // indirect
github.com/google/safehtml v0.1.0 // indirect
golang.org/x/exp/typeparams v0.0.0-20221212164502-fae10dda9338 // indirect
golang.org/x/sys v0.25.0 // indirect
gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15 // indirect
)

Просмотреть файл

@ -12,7 +12,6 @@ import (
"strings"
"golang.org/x/tools/go/analysis"
"golang.org/x/tools/internal/aliases"
"golang.org/x/tools/internal/analysisinternal"
)
@ -148,7 +147,7 @@ func embeddableType(o types.Object) bool {
// For embed.FS the underlying type is an implementation detail.
// As long as the named type resolves to embed.FS, it is OK.
if named, ok := aliases.Unalias(o.Type()).(*types.Named); ok {
if named, ok := types.Unalias(o.Type()).(*types.Named); ok {
obj := named.Obj()
if obj.Pkg() != nil && obj.Pkg().Path() == "embed" && obj.Name() == "FS" {
return true

Просмотреть файл

@ -9,17 +9,9 @@ import (
"golang.org/x/tools/go/analysis/analysistest"
"golang.org/x/tools/gopls/internal/analysis/fillreturns"
"golang.org/x/tools/internal/aliases"
)
func Test(t *testing.T) {
// TODO(golang/go#65294): update expectations and delete this
// check once we update go.mod to go1.23 so that
// gotypesalias=1 becomes the only supported mode.
if aliases.Enabled() {
t.Skip("expectations need updating for materialized aliases")
}
testdata := analysistest.TestData()
analysistest.RunWithSuggestedFixes(t, testdata, fillreturns.Analyzer, "a", "typeparams")
}

Просмотреть файл

@ -71,7 +71,7 @@ func complex() (*int, []int, [2]int, map[int]int) {
}
func structsAndInterfaces() (T, url.URL, T1, I, I1, io.Reader, Client, ast2.Stmt) {
return T{}, url.URL{}, T{}, nil, nil, nil, Client{}, nil // want "return values"
return T{}, url.URL{}, T1{}, nil, nil, nil, Client{}, nil // want "return values"
}
func m() (int, error) {

Просмотреть файл

@ -26,7 +26,6 @@ import (
"golang.org/x/tools/go/ast/astutil"
"golang.org/x/tools/gopls/internal/fuzzy"
"golang.org/x/tools/gopls/internal/util/safetoken"
"golang.org/x/tools/internal/aliases"
"golang.org/x/tools/internal/analysisinternal"
"golang.org/x/tools/internal/typeparams"
"golang.org/x/tools/internal/typesinternal"
@ -453,7 +452,7 @@ func populateValue(f *ast.File, pkg *types.Package, typ types.Type) ast.Expr {
}
case *types.Pointer:
switch aliases.Unalias(u.Elem()).(type) {
switch types.Unalias(u.Elem()).(type) {
case *types.Basic:
return &ast.CallExpr{
Fun: &ast.Ident{
@ -477,7 +476,7 @@ func populateValue(f *ast.File, pkg *types.Package, typ types.Type) ast.Expr {
}
case *types.Interface:
if param, ok := aliases.Unalias(typ).(*types.TypeParam); ok {
if param, ok := types.Unalias(typ).(*types.TypeParam); ok {
// *new(T) is the zero value of a type parameter T.
// TODO(adonovan): one could give a more specific zero
// value if the type has a core type that is, say,

Просмотреть файл

@ -17,7 +17,6 @@ import (
"golang.org/x/tools/go/analysis"
"golang.org/x/tools/go/ast/astutil"
"golang.org/x/tools/gopls/internal/util/typesutil"
"golang.org/x/tools/internal/aliases"
"golang.org/x/tools/internal/analysisinternal"
"golang.org/x/tools/internal/typesinternal"
)
@ -179,7 +178,7 @@ func fromCallExpr(fset *token.FileSet, info *types.Info, pos token.Pos, call *as
if !ok {
return nil
}
sig, ok := aliases.Unalias(tv.Type).(*types.Signature)
sig, ok := types.Unalias(tv.Type).(*types.Signature)
if !ok {
return nil
}
@ -344,7 +343,7 @@ func ifaceType(e ast.Expr, info *types.Info) *types.TypeName {
}
func ifaceObjFromType(t types.Type) *types.TypeName {
named, ok := aliases.Unalias(t).(*types.Named)
named, ok := types.Unalias(t).(*types.Named)
if !ok {
return nil
}
@ -373,11 +372,11 @@ func concreteType(e ast.Expr, info *types.Info) (*types.Named, bool) {
return nil, false
}
typ := tv.Type
ptr, isPtr := aliases.Unalias(typ).(*types.Pointer)
ptr, isPtr := types.Unalias(typ).(*types.Pointer)
if isPtr {
typ = ptr.Elem()
}
named, ok := aliases.Unalias(typ).(*types.Named)
named, ok := types.Unalias(typ).(*types.Named)
if !ok {
return nil, false
}

Просмотреть файл

@ -18,7 +18,6 @@ import (
"golang.org/x/tools/go/analysis"
"golang.org/x/tools/go/ast/astutil"
"golang.org/x/tools/gopls/internal/util/safetoken"
"golang.org/x/tools/internal/aliases"
"golang.org/x/tools/internal/analysisinternal"
)
@ -318,7 +317,7 @@ func newFunctionDeclaration(path []ast.Node, file *ast.File, pkg *types.Package,
func typeToArgName(ty types.Type) string {
s := types.Default(ty).String()
switch t := aliases.Unalias(ty).(type) {
switch t := types.Unalias(ty).(type) {
case *types.Basic:
// use first letter in type name for basic types
return s[0:1]

Просмотреть файл

@ -54,7 +54,6 @@ import (
"golang.org/x/tools/go/types/objectpath"
"golang.org/x/tools/gopls/internal/util/frob"
"golang.org/x/tools/gopls/internal/util/safetoken"
"golang.org/x/tools/internal/aliases"
)
// An Index records the non-empty method sets of all package-level
@ -305,7 +304,7 @@ func methodSetInfo(t types.Type, setIndexInfo func(*gobMethod, *types.Func)) gob
// EnsurePointer wraps T in a types.Pointer if T is a named, non-interface type.
// This is useful to make sure you consider a named type's full method set.
func EnsurePointer(T types.Type) types.Type {
if _, ok := aliases.Unalias(T).(*types.Named); ok && !types.IsInterface(T) {
if _, ok := types.Unalias(T).(*types.Named); ok && !types.IsInterface(T) {
return types.NewPointer(T)
}
@ -330,8 +329,8 @@ func fingerprint(method *types.Func) (string, bool) {
var fprint func(t types.Type)
fprint = func(t types.Type) {
switch t := t.(type) {
case *aliases.Alias:
fprint(aliases.Unalias(t))
case *types.Alias:
fprint(types.Unalias(t))
case *types.Named:
tname := t.Obj()

Просмотреть файл

@ -40,7 +40,6 @@ import (
goplsastutil "golang.org/x/tools/gopls/internal/util/astutil"
"golang.org/x/tools/gopls/internal/util/safetoken"
"golang.org/x/tools/gopls/internal/util/typesutil"
"golang.org/x/tools/internal/aliases"
"golang.org/x/tools/internal/event"
"golang.org/x/tools/internal/imports"
"golang.org/x/tools/internal/stdlib"
@ -1640,7 +1639,7 @@ func (c *completer) lexical(ctx context.Context) error {
}
if c.inference.objType != nil {
if named, ok := aliases.Unalias(typesinternal.Unpointer(c.inference.objType)).(*types.Named); ok {
if named, ok := types.Unalias(typesinternal.Unpointer(c.inference.objType)).(*types.Named); ok {
// If we expected a named type, check the type's package for
// completion items. This is useful when the current file hasn't
// imported the type's package yet.
@ -1714,7 +1713,7 @@ func (c *completer) injectType(ctx context.Context, t types.Type) {
// considered via a lexical search, so we need to directly inject
// them. Also allow generic types since lexical search does not
// infer instantiated versions of them.
if named, ok := aliases.Unalias(t).(*types.Named); !ok || named.TypeParams().Len() > 0 {
if named, ok := types.Unalias(t).(*types.Named); !ok || named.TypeParams().Len() > 0 {
// If our expected type is "[]int", this will add a literal
// candidate of "[]int{}".
c.literal(ctx, t, nil)
@ -1898,7 +1897,7 @@ func (c *completer) structLiteralFieldName(ctx context.Context) error {
}
// Add struct fields.
if t, ok := aliases.Unalias(clInfo.clType).(*types.Struct); ok {
if t, ok := types.Unalias(clInfo.clType).(*types.Struct); ok {
const deltaScore = 0.0001
for i := 0; i < t.NumFields(); i++ {
field := t.Field(i)

Просмотреть файл

@ -17,7 +17,6 @@ import (
"golang.org/x/tools/gopls/internal/golang/completion/snippet"
"golang.org/x/tools/gopls/internal/protocol"
"golang.org/x/tools/gopls/internal/util/safetoken"
"golang.org/x/tools/internal/aliases"
"golang.org/x/tools/internal/event"
"golang.org/x/tools/internal/imports"
)
@ -61,7 +60,7 @@ func (c *completer) item(ctx context.Context, cand candidate) (CompletionItem, e
}
if isTypeName(obj) && c.wantTypeParams() {
x := cand.obj.(*types.TypeName)
if named, ok := aliases.Unalias(x.Type()).(*types.Named); ok {
if named, ok := types.Unalias(x.Type()).(*types.Named); ok {
tp := named.TypeParams()
label += golang.FormatTypeParams(tp)
insert = label // maintain invariant above (label == insert)
@ -412,8 +411,8 @@ func inferableTypeParams(sig *types.Signature) map[*types.TypeParam]bool {
}
case *types.TypeParam:
free[t] = true
case *aliases.Alias:
visit(aliases.Unalias(t))
case *types.Alias:
visit(types.Unalias(t))
case *types.Named:
targs := t.TypeArgs()
for i := 0; i < targs.Len(); i++ {

Просмотреть файл

@ -14,7 +14,6 @@ import (
"golang.org/x/tools/gopls/internal/golang"
"golang.org/x/tools/gopls/internal/golang/completion/snippet"
"golang.org/x/tools/gopls/internal/protocol"
"golang.org/x/tools/internal/aliases"
"golang.org/x/tools/internal/event"
"golang.org/x/tools/internal/typesinternal"
)
@ -55,9 +54,9 @@ func (c *completer) literal(ctx context.Context, literalType types.Type, imp *im
// TODO(adonovan): think about aliases:
// they should probably be treated more like Named.
// Should this use Deref not Unpointer?
if is[*types.Named](aliases.Unalias(literalType)) &&
if is[*types.Named](types.Unalias(literalType)) &&
expType != nil &&
!is[*types.Named](aliases.Unalias(typesinternal.Unpointer(expType))) {
!is[*types.Named](types.Unalias(typesinternal.Unpointer(expType))) {
return
}
@ -200,7 +199,7 @@ func (c *completer) functionLiteral(ctx context.Context, sig *types.Signature, m
name = p.Name()
)
if tp, _ := aliases.Unalias(p.Type()).(*types.TypeParam); tp != nil && !c.typeParamInScope(tp) {
if tp, _ := types.Unalias(p.Type()).(*types.TypeParam); tp != nil && !c.typeParamInScope(tp) {
hasTypeParams = true
}
@ -291,7 +290,7 @@ func (c *completer) functionLiteral(ctx context.Context, sig *types.Signature, m
typeStr = strings.Replace(typeStr, "[]", "...", 1)
}
if tp, ok := aliases.Unalias(p.Type()).(*types.TypeParam); ok && !c.typeParamInScope(tp) {
if tp, ok := types.Unalias(p.Type()).(*types.TypeParam); ok && !c.typeParamInScope(tp) {
snip.WritePlaceholder(func(snip *snippet.Builder) {
snip.WriteText(typeStr)
})
@ -312,7 +311,7 @@ func (c *completer) functionLiteral(ctx context.Context, sig *types.Signature, m
var resultHasTypeParams bool
for i := 0; i < results.Len(); i++ {
if tp, ok := aliases.Unalias(results.At(i).Type()).(*types.TypeParam); ok && !c.typeParamInScope(tp) {
if tp, ok := types.Unalias(results.At(i).Type()).(*types.TypeParam); ok && !c.typeParamInScope(tp) {
resultHasTypeParams = true
}
}
@ -345,7 +344,7 @@ func (c *completer) functionLiteral(ctx context.Context, sig *types.Signature, m
}
return
}
if tp, ok := aliases.Unalias(r.Type()).(*types.TypeParam); ok && !c.typeParamInScope(tp) {
if tp, ok := types.Unalias(r.Type()).(*types.TypeParam); ok && !c.typeParamInScope(tp) {
snip.WritePlaceholder(func(snip *snippet.Builder) {
snip.WriteText(text)
})
@ -519,7 +518,7 @@ func (c *completer) typeNameSnippet(literalType types.Type, qf types.Qualifier)
typeName string
// TODO(adonovan): think more about aliases.
// They should probably be treated more like Named.
named, _ = aliases.Unalias(literalType).(*types.Named)
named, _ = types.Unalias(literalType).(*types.Named)
)
if named != nil && named.Obj() != nil && named.TypeParams().Len() > 0 && !c.fullyInstantiated(named) {
@ -567,7 +566,7 @@ func (c *completer) fullyInstantiated(t *types.Named) bool {
for i := 0; i < tas.Len(); i++ {
// TODO(adonovan) think about generic aliases.
switch ta := aliases.Unalias(tas.At(i)).(type) {
switch ta := types.Unalias(tas.At(i)).(type) {
case *types.TypeParam:
// A *TypeParam only counts as specified if it is currently in
// scope (i.e. we are in a generic definition).

Просмотреть файл

@ -21,7 +21,6 @@ import (
"golang.org/x/tools/gopls/internal/golang/completion/snippet"
"golang.org/x/tools/gopls/internal/protocol"
"golang.org/x/tools/gopls/internal/util/safetoken"
"golang.org/x/tools/internal/aliases"
"golang.org/x/tools/internal/event"
"golang.org/x/tools/internal/imports"
"golang.org/x/tools/internal/typesinternal"
@ -465,7 +464,7 @@ func (a *postfixTmplArgs) VarName(t types.Type, nonNamedDefault string) string {
// go/types predicates are undefined on types.Typ[types.Invalid].
if !types.Identical(t, types.Typ[types.Invalid]) && types.Implements(t, errorIntf) {
name = "err"
} else if !is[*types.Named](aliases.Unalias(typesinternal.Unpointer(t))) {
} else if !is[*types.Named](types.Unalias(typesinternal.Unpointer(t))) {
name = nonNamedDefault
}

Просмотреть файл

@ -13,7 +13,6 @@ import (
"golang.org/x/tools/gopls/internal/golang"
"golang.org/x/tools/gopls/internal/protocol"
"golang.org/x/tools/gopls/internal/util/safetoken"
"golang.org/x/tools/internal/aliases"
"golang.org/x/tools/internal/diff"
"golang.org/x/tools/internal/typeparams"
)
@ -65,7 +64,7 @@ func eachField(T types.Type, fn func(*types.Var)) {
func typeIsValid(typ types.Type) bool {
// Check named types separately, because we don't want
// to call Underlying() on them to avoid problems with recursive types.
if _, ok := aliases.Unalias(typ).(*types.Named); ok {
if _, ok := types.Unalias(typ).(*types.Named); ok {
return true
}
@ -140,7 +139,7 @@ func isPkgName(obj types.Object) bool { return is[*types.PkgName](obj) }
// It returns false for a Named type whose Underlying is a Pointer.
//
// TODO(adonovan): shouldn't this use CoreType(T)?
func isPointer(T types.Type) bool { return is[*types.Pointer](aliases.Unalias(T)) }
func isPointer(T types.Type) bool { return is[*types.Pointer](types.Unalias(T)) }
// isEmptyInterface whether T is a (possibly Named or Alias) empty interface
// type, such that every type is assignable to T.
@ -156,7 +155,7 @@ func isEmptyInterface(T types.Type) bool {
}
func isUntyped(T types.Type) bool {
if basic, ok := aliases.Unalias(T).(*types.Basic); ok {
if basic, ok := types.Unalias(T).(*types.Basic); ok {
return basic.Info()&types.IsUntyped > 0
}
return false
@ -321,8 +320,8 @@ func (c *completer) editText(from, to token.Pos, newText string) ([]protocol.Tex
// assignableTo is like types.AssignableTo, but returns false if
// either type is invalid.
func assignableTo(x, to types.Type) bool {
if aliases.Unalias(x) == types.Typ[types.Invalid] ||
aliases.Unalias(to) == types.Typ[types.Invalid] {
if types.Unalias(x) == types.Typ[types.Invalid] ||
types.Unalias(to) == types.Typ[types.Invalid] {
return false
}
@ -332,8 +331,8 @@ func assignableTo(x, to types.Type) bool {
// convertibleTo is like types.ConvertibleTo, but returns false if
// either type is invalid.
func convertibleTo(x, to types.Type) bool {
if aliases.Unalias(x) == types.Typ[types.Invalid] ||
aliases.Unalias(to) == types.Typ[types.Invalid] {
if types.Unalias(x) == types.Typ[types.Invalid] ||
types.Unalias(to) == types.Typ[types.Invalid] {
return false
}

Просмотреть файл

@ -37,7 +37,6 @@ import (
"golang.org/x/tools/gopls/internal/util/bug"
"golang.org/x/tools/gopls/internal/util/safetoken"
"golang.org/x/tools/gopls/internal/util/typesutil"
"golang.org/x/tools/internal/aliases"
"golang.org/x/tools/internal/event"
"golang.org/x/tools/internal/stdlib"
"golang.org/x/tools/internal/tokeninternal"
@ -381,7 +380,7 @@ func hover(ctx context.Context, snapshot *cache.Snapshot, fh file.Handle, pp pro
// (2) we lose inline comments
// Furthermore, we include a summary of their method set.
_, isTypeName := obj.(*types.TypeName)
_, isTypeParam := aliases.Unalias(obj.Type()).(*types.TypeParam)
_, isTypeParam := types.Unalias(obj.Type()).(*types.TypeParam)
if isTypeName && !isTypeParam {
spec, ok := spec.(*ast.TypeSpec)
if !ok {
@ -1024,7 +1023,7 @@ func objectString(obj types.Object, qf types.Qualifier, declPos token.Pos, file
}
// Special formatting cases.
switch typ := aliases.Unalias(obj.Type()).(type) {
switch typ := types.Unalias(obj.Type()).(type) {
case *types.Named:
// Try to add a formatted duration as an inline comment.
pkg := typ.Obj().Pkg()

Просмотреть файл

@ -9,7 +9,6 @@ import (
"go/ast"
"go/types"
"golang.org/x/tools/internal/aliases"
"golang.org/x/tools/internal/typesinternal"
)
@ -22,7 +21,7 @@ var ErrNoIdentFound = errors.New("no identifier found")
// If no such signature exists, it returns nil.
func inferredSignature(info *types.Info, id *ast.Ident) *types.Signature {
inst := info.Instances[id]
sig, _ := aliases.Unalias(inst.Type).(*types.Signature)
sig, _ := types.Unalias(inst.Type).(*types.Signature)
return sig
}
@ -41,7 +40,7 @@ func searchForEnclosing(info *types.Info, path []ast.Node) *types.TypeName {
// Keep track of the last exported type seen.
var exported *types.TypeName
if named, ok := aliases.Unalias(recv).(*types.Named); ok && named.Obj().Exported() {
if named, ok := types.Unalias(recv).(*types.Named); ok && named.Obj().Exported() {
exported = named.Obj()
}
// We don't want the last element, as that's the field or
@ -49,7 +48,7 @@ func searchForEnclosing(info *types.Info, path []ast.Node) *types.TypeName {
for _, index := range sel.Index()[:len(sel.Index())-1] {
if r, ok := recv.Underlying().(*types.Struct); ok {
recv = typesinternal.Unpointer(r.Field(index).Type())
if named, ok := aliases.Unalias(recv).(*types.Named); ok && named.Obj().Exported() {
if named, ok := types.Unalias(recv).(*types.Named); ok && named.Obj().Exported() {
exported = named.Obj()
}
}
@ -66,7 +65,7 @@ func searchForEnclosing(info *types.Info, path []ast.Node) *types.TypeName {
// a single non-error result, and ignoring built-in named types.
func typeToObject(typ types.Type) *types.TypeName {
switch typ := typ.(type) {
case *aliases.Alias:
case *types.Alias:
return typ.Obj()
case *types.Named:
// TODO(rfindley): this should use typeparams.NamedTypeOrigin.

Просмотреть файл

@ -66,7 +66,6 @@ import (
"golang.org/x/tools/gopls/internal/protocol"
"golang.org/x/tools/gopls/internal/util/bug"
"golang.org/x/tools/gopls/internal/util/safetoken"
"golang.org/x/tools/internal/aliases"
"golang.org/x/tools/internal/diff"
"golang.org/x/tools/internal/event"
"golang.org/x/tools/internal/typesinternal"
@ -353,7 +352,7 @@ func renameOrdinary(ctx context.Context, snapshot *cache.Snapshot, f file.Handle
// of the type parameters, unlike methods).
switch obj.(type) { // avoid "obj :=" since cases reassign the var
case *types.TypeName:
if _, ok := aliases.Unalias(obj.Type()).(*types.TypeParam); ok {
if _, ok := types.Unalias(obj.Type()).(*types.TypeParam); ok {
// As with capitalized function parameters below, type parameters are
// local.
goto skipObjectPath

Просмотреть файл

@ -45,7 +45,6 @@ import (
"golang.org/x/tools/go/ast/astutil"
"golang.org/x/tools/gopls/internal/cache"
"golang.org/x/tools/gopls/internal/util/safetoken"
"golang.org/x/tools/internal/aliases"
"golang.org/x/tools/internal/typeparams"
"golang.org/x/tools/internal/typesinternal"
"golang.org/x/tools/refactor/satisfy"
@ -504,7 +503,7 @@ func (r *renamer) checkStructField(from *types.Var) {
if from.Anonymous() {
if named, ok := from.Type().(*types.Named); ok {
r.check(named.Obj())
} else if named, ok := aliases.Unalias(typesinternal.Unpointer(from.Type())).(*types.Named); ok {
} else if named, ok := types.Unalias(typesinternal.Unpointer(from.Type())).(*types.Named); ok {
r.check(named.Obj())
}
}
@ -813,7 +812,7 @@ func (r *renamer) checkMethod(from *types.Func) {
var iface string
I := recv(imeth).Type()
if named, ok := aliases.Unalias(I).(*types.Named); ok {
if named, ok := types.Unalias(I).(*types.Named); ok {
pos = named.Obj().Pos()
iface = "interface " + named.Obj().Name()
} else {

Просмотреть файл

@ -28,7 +28,6 @@ import (
"golang.org/x/tools/gopls/internal/protocol/semtok"
"golang.org/x/tools/gopls/internal/util/bug"
"golang.org/x/tools/gopls/internal/util/safetoken"
"golang.org/x/tools/internal/aliases"
"golang.org/x/tools/internal/event"
)
@ -573,13 +572,13 @@ func (tv *tokenVisitor) ident(id *ast.Ident) {
case *types.PkgName:
emit(semtok.TokNamespace)
case *types.TypeName: // could be a TypeParam
if is[*types.TypeParam](aliases.Unalias(obj.Type())) {
if is[*types.TypeParam](types.Unalias(obj.Type())) {
emit(semtok.TokTypeParam)
} else {
emit(semtok.TokType, appendTypeModifiers(nil, obj)...)
}
case *types.Var:
if is[*types.Signature](aliases.Unalias(obj.Type())) {
if is[*types.Signature](types.Unalias(obj.Type())) {
emit(semtok.TokFunction)
} else if tv.isParam(obj.Pos()) {
// variable, unless use.pos is the pos of a Field in an ancestor FuncDecl

Просмотреть файл

@ -20,7 +20,6 @@ import (
"golang.org/x/tools/go/ast/astutil"
"golang.org/x/tools/go/packages"
"golang.org/x/tools/internal/aliases"
// (does not depend on gopls itself)
)
@ -125,7 +124,7 @@ func (l *fieldLoader) loadMethod(pkg *packages.Package, m *types.Func) (*Command
if i == 0 {
// Lazy check that the first argument is a context. We could relax this,
// but then the generated code gets more complicated.
if named, ok := aliases.Unalias(fld.Type).(*types.Named); !ok || named.Obj().Name() != "Context" || named.Obj().Pkg().Path() != "context" {
if named, ok := types.Unalias(fld.Type).(*types.Named); !ok || named.Obj().Name() != "Context" || named.Obj().Pkg().Path() != "context" {
return nil, fmt.Errorf("first method parameter must be context.Context")
}
// Skip the context argument, as it is implied.

Просмотреть файл

@ -7,7 +7,6 @@ package misc
import (
"testing"
"golang.org/x/tools/internal/aliases"
"golang.org/x/tools/internal/testenv"
. "golang.org/x/tools/gopls/internal/test/integration"
@ -23,12 +22,6 @@ func TestStaticcheckGenerics(t *testing.T) {
// TODO(adonovan): reenable once dominikh/go-tools#1494 is fixed.
t.Skip("disabled until buildir supports range-over-func (dominikh/go-tools#1494)")
// TODO(golang/go#65249): re-enable and fix this test once we
// update go.mod to go1.23 so that gotypesalias=1 becomes the default.
if aliases.Enabled() {
t.Skip("staticheck doesn't yet support aliases (dominikh/go-tools#1523)")
}
const files = `
-- go.mod --
module mod.com
@ -101,12 +94,6 @@ func TestStaticcheckRelatedInfo(t *testing.T) {
// TODO(adonovan): reenable once dominikh/go-tools#1494 is fixed.
t.Skip("disabled until buildir supports range-over-func (dominikh/go-tools#1494)")
// TODO(golang/go#65249): re-enable and fix this test once we
// update go.mod to go1.23 so that gotypesalias=1 becomes the default.
if aliases.Enabled() {
t.Skip("staticheck doesn't yet support aliases (dominikh/go-tools#1523)")
}
const files = `
-- go.mod --
module mod.test

Просмотреть файл

@ -28,7 +28,7 @@ import (
func NewAlias(enabled bool, pos token.Pos, pkg *types.Package, name string, rhs types.Type, tparams []*types.TypeParam) *types.TypeName {
if enabled {
tname := types.NewTypeName(pos, pkg, name, nil)
newAlias(tname, rhs, tparams)
SetTypeParams(types.NewAlias(tname, rhs), tparams)
return tname
}
if len(tparams) > 0 {

Просмотреть файл

@ -1,37 +0,0 @@
// 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 (
"go/types"
)
// Alias is a placeholder for a go/types.Alias for <=1.21.
// It will never be created by go/types.
type Alias struct{}
func (*Alias) String() string { panic("unreachable") }
func (*Alias) Underlying() types.Type { panic("unreachable") }
func (*Alias) Obj() *types.TypeName { panic("unreachable") }
func Rhs(alias *Alias) types.Type { panic("unreachable") }
func TypeParams(alias *Alias) *types.TypeParamList { panic("unreachable") }
func SetTypeParams(alias *Alias, tparams []*types.TypeParam) { panic("unreachable") }
func TypeArgs(alias *Alias) *types.TypeList { panic("unreachable") }
func Origin(alias *Alias) *Alias { panic("unreachable") }
// Unalias returns the type t for go <=1.21.
func Unalias(t types.Type) types.Type { return t }
func newAlias(name *types.TypeName, rhs types.Type, tparams []*types.TypeParam) *Alias {
panic("unreachable")
}
// Enabled reports whether [NewAlias] should create [types.Alias] types.
//
// Before go1.22, this function always returns false.
func Enabled() bool { return false }

Просмотреть файл

@ -2,9 +2,6 @@
// 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 (
@ -14,22 +11,19 @@ import (
"go/types"
)
// 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 Rhs(alias *Alias) types.Type {
func Rhs(alias *types.Alias) types.Type {
if alias, ok := any(alias).(interface{ Rhs() types.Type }); ok {
return alias.Rhs() // go1.23+
}
// go1.22's Alias didn't have the Rhs method,
// so Unalias is the best we can do.
return Unalias(alias)
return types.Unalias(alias)
}
// TypeParams returns the type parameter list of the alias.
func TypeParams(alias *Alias) *types.TypeParamList {
func TypeParams(alias *types.Alias) *types.TypeParamList {
if alias, ok := any(alias).(interface{ TypeParams() *types.TypeParamList }); ok {
return alias.TypeParams() // go1.23+
}
@ -37,7 +31,7 @@ func TypeParams(alias *Alias) *types.TypeParamList {
}
// SetTypeParams sets the type parameters of the alias type.
func SetTypeParams(alias *Alias, tparams []*types.TypeParam) {
func SetTypeParams(alias *types.Alias, tparams []*types.TypeParam) {
if alias, ok := any(alias).(interface {
SetTypeParams(tparams []*types.TypeParam)
}); ok {
@ -48,7 +42,7 @@ func SetTypeParams(alias *Alias, tparams []*types.TypeParam) {
}
// TypeArgs returns the type arguments used to instantiate the Alias type.
func TypeArgs(alias *Alias) *types.TypeList {
func TypeArgs(alias *types.Alias) *types.TypeList {
if alias, ok := any(alias).(interface{ TypeArgs() *types.TypeList }); ok {
return alias.TypeArgs() // go1.23+
}
@ -57,25 +51,13 @@ func TypeArgs(alias *Alias) *types.TypeList {
// Origin returns the generic Alias type of which alias is an instance.
// If alias is not an instance of a generic alias, Origin returns alias.
func Origin(alias *Alias) *Alias {
func Origin(alias *types.Alias) *types.Alias {
if alias, ok := any(alias).(interface{ Origin() *types.Alias }); ok {
return alias.Origin() // go1.23+
}
return alias // not an instance of a generic alias (go1.22)
}
// Unalias is a wrapper of types.Unalias.
func Unalias(t types.Type) types.Type { return types.Unalias(t) }
// newAlias is an internal alias around types.NewAlias.
// Direct usage is discouraged as the moment.
// Try to use NewAlias instead.
func newAlias(tname *types.TypeName, rhs types.Type, tparams []*types.TypeParam) *Alias {
a := types.NewAlias(tname, rhs)
SetTypeParams(a, tparams)
return a
}
// Enabled reports whether [NewAlias] should create [types.Alias] types.
//
// This function is expensive! Call it sparingly.

Просмотреть файл

@ -15,13 +15,10 @@ import (
"golang.org/x/tools/internal/testenv"
)
// Assert that Obj exists on Alias.
var _ func(*aliases.Alias) *types.TypeName = (*aliases.Alias).Obj
// TestNewAlias tests that alias.NewAlias creates an alias of a type
// whose underlying and Unaliased type is *Named.
// When gotypesalias=1 (or unset) and GoVersion >= 1.22, the type will
// be an *aliases.Alias.
// be an *types.Alias.
func TestNewAlias(t *testing.T) {
const source = `
package p
@ -66,12 +63,12 @@ func TestNewAlias(t *testing.T) {
if got, want := A.Type().Underlying(), tv.Type; got != want {
t.Errorf("Expected A.Type().Underlying()==%q. got %q", want, got)
}
if got, want := aliases.Unalias(A.Type()), tv.Type; got != want {
if got, want := types.Unalias(A.Type()), tv.Type; got != want {
t.Errorf("Expected Unalias(A)==%q. got %q", want, got)
}
if testenv.Go1Point() >= 22 && godebug != "gotypesalias=0" {
if _, ok := A.Type().(*aliases.Alias); !ok {
if _, ok := A.Type().(*types.Alias); !ok {
t.Errorf("Expected A.Type() to be a types.Alias(). got %q", A.Type())
}
}
@ -125,11 +122,11 @@ func TestNewParameterizedAlias(t *testing.T) {
if got, want := A.Type().Underlying(), ptrT; !types.Identical(got, want) {
t.Errorf("A.Type().Underlying (%q) is not identical to %q", got, want)
}
if got, want := aliases.Unalias(A.Type()), ptrT; !types.Identical(got, want) {
if got, want := types.Unalias(A.Type()), ptrT; !types.Identical(got, want) {
t.Errorf("Unalias(A)==%q is not identical to %q", got, want)
}
if _, ok := A.Type().(*aliases.Alias); !ok {
if _, ok := A.Type().(*types.Alias); !ok {
t.Errorf("Expected A.Type() to be a types.Alias(). got %q", A.Type())
}
@ -150,7 +147,7 @@ func TestNewParameterizedAlias(t *testing.T) {
if got, want := tv.Type.Underlying(), ptrNamed; !types.Identical(got, want) {
t.Errorf("A[Named].Type().Underlying (%q) is not identical to %q", got, want)
}
if got, want := aliases.Unalias(tv.Type), ptrNamed; !types.Identical(got, want) {
if got, want := types.Unalias(tv.Type), ptrNamed; !types.Identical(got, want) {
t.Errorf("Unalias(A[Named])==%q is not identical to %q", got, want)
}
}

Просмотреть файл

@ -17,7 +17,6 @@ import (
"strconv"
"golang.org/x/tools/go/analysis"
"golang.org/x/tools/internal/aliases"
)
func TypeErrorEndPos(fset *token.FileSet, src []byte, start token.Pos) token.Pos {
@ -34,7 +33,7 @@ func TypeErrorEndPos(fset *token.FileSet, src []byte, start token.Pos) token.Pos
func ZeroValue(f *ast.File, pkg *types.Package, typ types.Type) ast.Expr {
// TODO(adonovan): think about generics, and also generic aliases.
under := aliases.Unalias(typ)
under := types.Unalias(typ)
// Don't call Underlying unconditionally: although it removes
// Named and Alias, it also removes TypeParam.
if n, ok := under.(*types.Named); ok {

Просмотреть файл

@ -19,8 +19,6 @@ import (
"go/constant"
"go/token"
"go/types"
"golang.org/x/tools/internal/aliases"
)
// Changes reports on the differences between the APIs of the old and new packages.
@ -208,7 +206,7 @@ func (d *differ) typeChanged(obj types.Object, part string, old, new types.Type)
// Since these can change without affecting compatibility, we don't want users to
// be distracted by them, so we remove them.
func removeNamesFromSignature(t types.Type) types.Type {
t = aliases.Unalias(t)
t = types.Unalias(t)
sig, ok := t.(*types.Signature)
if !ok {
return t
@ -218,7 +216,7 @@ func removeNamesFromSignature(t types.Type) types.Type {
var vars []*types.Var
for i := 0; i < p.Len(); i++ {
v := p.At(i)
vars = append(vars, types.NewVar(v.Pos(), v.Pkg(), "", aliases.Unalias(v.Type())))
vars = append(vars, types.NewVar(v.Pos(), v.Pkg(), "", types.Unalias(v.Type())))
}
return types.NewTuple(vars...)
}

Просмотреть файл

@ -9,13 +9,12 @@ import (
"go/types"
"reflect"
"golang.org/x/tools/internal/aliases"
"golang.org/x/tools/internal/typesinternal"
)
func (d *differ) checkCompatible(otn *types.TypeName, old, new types.Type) {
old = aliases.Unalias(old)
new = aliases.Unalias(new)
old = types.Unalias(old)
new = types.Unalias(new)
switch old := old.(type) {
case *types.Interface:
if new, ok := new.(*types.Interface); ok {
@ -292,7 +291,7 @@ func (d *differ) checkMethodSet(otn *types.TypeName, oldt, newt types.Type, addc
oldMethodSet := exportedMethods(oldt)
newMethodSet := exportedMethods(newt)
msname := otn.Name()
if _, ok := aliases.Unalias(oldt).(*types.Pointer); ok {
if _, ok := types.Unalias(oldt).(*types.Pointer); ok {
msname = "*" + msname
}
for name, oldMethod := range oldMethodSet {

Просмотреть файл

@ -7,8 +7,6 @@ package apidiff
import (
"go/types"
"sort"
"golang.org/x/tools/internal/aliases"
)
// Two types are correspond if they are identical except for defined types,
@ -33,8 +31,8 @@ func (d *differ) correspond(old, new types.Type) bool {
// Compare this to the implementation of go/types.Identical.
func (d *differ) corr(old, new types.Type, p *ifacePair) bool {
// Structure copied from types.Identical.
old = aliases.Unalias(old)
new = aliases.Unalias(new)
old = types.Unalias(old)
new = types.Unalias(new)
switch old := old.(type) {
case *types.Basic:
return types.Identical(old, new)

Просмотреть файл

@ -18,7 +18,6 @@ import (
"golang.org/x/tools/go/analysis/analysistest"
"golang.org/x/tools/go/packages"
"golang.org/x/tools/internal/aliases"
"golang.org/x/tools/internal/facts"
"golang.org/x/tools/internal/testenv"
)
@ -361,7 +360,7 @@ func find(p *types.Package, expr string) types.Object {
if err != nil {
return nil
}
if n, ok := aliases.Unalias(tv.Type).(*types.Named); ok {
if n, ok := types.Unalias(tv.Type).(*types.Named); ok {
return n.Obj()
}
return nil

Просмотреть файл

@ -6,8 +6,6 @@ package facts
import (
"go/types"
"golang.org/x/tools/internal/aliases"
)
// importMap computes the import map for a package by traversing the
@ -47,8 +45,8 @@ func importMap(imports []*types.Package) map[string]*types.Package {
addType = func(T types.Type) {
switch T := T.(type) {
case *aliases.Alias:
addType(aliases.Unalias(T))
case *types.Alias:
addType(types.Unalias(T))
case *types.Basic:
// nop
case *types.Named:

Просмотреть файл

@ -18,7 +18,6 @@ import (
"strings"
"testing"
"golang.org/x/tools/internal/aliases"
"golang.org/x/tools/internal/gcimporter"
)
@ -31,8 +30,8 @@ func fileLine(fset *token.FileSet, obj types.Object) string {
}
func equalType(x, y types.Type) error {
x = aliases.Unalias(x)
y = aliases.Unalias(y)
x = types.Unalias(x)
y = types.Unalias(y)
if reflect.TypeOf(x) != reflect.TypeOf(y) {
return fmt.Errorf("unequal kinds: %T vs %T", x, y)
}

Просмотреть файл

@ -27,7 +27,6 @@ import (
"testing"
"time"
"golang.org/x/tools/internal/aliases"
"golang.org/x/tools/internal/goroot"
"golang.org/x/tools/internal/testenv"
)
@ -425,7 +424,7 @@ func TestImportedTypes(t *testing.T) {
t.Errorf("%s: got %q; want %q", test.name, got, test.want)
}
if named, _ := aliases.Unalias(obj.Type()).(*types.Named); named != nil {
if named, _ := types.Unalias(obj.Type()).(*types.Named); named != nil {
verifyInterfaceMethodRecvs(t, named, 0)
}
}
@ -508,7 +507,7 @@ func verifyInterfaceMethodRecvs(t *testing.T, named *types.Named, level int) {
// check embedded interfaces (if they are named, too)
for i := 0; i < iface.NumEmbeddeds(); i++ {
// embedding of interfaces cannot have cycles; recursion will terminate
if etype, _ := aliases.Unalias(iface.EmbeddedType(i)).(*types.Named); etype != nil {
if etype, _ := types.Unalias(iface.EmbeddedType(i)).(*types.Named); etype != nil {
verifyInterfaceMethodRecvs(t, etype, level+1)
}
}
@ -528,7 +527,7 @@ func TestIssue5815(t *testing.T) {
t.Errorf("no pkg for %s", obj)
}
if tname, _ := obj.(*types.TypeName); tname != nil {
named := aliases.Unalias(tname.Type()).(*types.Named)
named := types.Unalias(tname.Type()).(*types.Named)
for i := 0; i < named.NumMethods(); i++ {
m := named.Method(i)
if m.Pkg() == nil {
@ -628,7 +627,7 @@ func TestIssue13898(t *testing.T) {
// look for go/types.Object type
obj := lookupObj(t, goTypesPkg.Scope(), "Object")
typ, ok := aliases.Unalias(obj.Type()).(*types.Named)
typ, ok := types.Unalias(obj.Type()).(*types.Named)
if !ok {
t.Fatalf("go/types.Object type is %v; wanted named type", typ)
}

Просмотреть файл

@ -725,13 +725,13 @@ func (p *iexporter) doDecl(obj types.Object) {
case *types.TypeName:
t := obj.Type()
if tparam, ok := aliases.Unalias(t).(*types.TypeParam); ok {
if tparam, ok := types.Unalias(t).(*types.TypeParam); ok {
w.tag(typeParamTag)
w.pos(obj.Pos())
constraint := tparam.Constraint()
if p.version >= iexportVersionGo1_18 {
implicit := false
if iface, _ := aliases.Unalias(constraint).(*types.Interface); iface != nil {
if iface, _ := types.Unalias(constraint).(*types.Interface); iface != nil {
implicit = iface.IsImplicit()
}
w.bool(implicit)
@ -741,7 +741,7 @@ func (p *iexporter) doDecl(obj types.Object) {
}
if obj.IsAlias() {
alias, materialized := t.(*aliases.Alias) // may fail when aliases are not enabled
alias, materialized := t.(*types.Alias) // may fail when aliases are not enabled
var tparams *types.TypeParamList
if materialized {
@ -975,7 +975,7 @@ func (w *exportWriter) doTyp(t types.Type, pkg *types.Package) {
}()
}
switch t := t.(type) {
case *aliases.Alias:
case *types.Alias:
if targs := aliases.TypeArgs(t); targs.Len() > 0 {
w.startType(instanceType)
w.pos(t.Obj().Pos())
@ -1091,7 +1091,7 @@ func (w *exportWriter) doTyp(t types.Type, pkg *types.Package) {
for i := 0; i < n; i++ {
ft := t.EmbeddedType(i)
tPkg := pkg
if named, _ := aliases.Unalias(ft).(*types.Named); named != nil {
if named, _ := types.Unalias(ft).(*types.Named); named != nil {
w.pos(named.Obj().Pos())
} else {
w.pos(token.NoPos)

Просмотреть файл

@ -344,8 +344,8 @@ func cmpObj(x, y types.Object) error {
// situations where the type name is not referenced by the underlying or
// any other top-level declarations. Therefore, we must explicitly compare
// named types here, before passing their underlying types into equalType.
xn, _ := aliases.Unalias(xt).(*types.Named)
yn, _ := aliases.Unalias(yt).(*types.Named)
xn, _ := types.Unalias(xt).(*types.Named)
yn, _ := types.Unalias(yt).(*types.Named)
if (xn == nil) != (yn == nil) {
return fmt.Errorf("mismatching types: %T vs %T", xt, yt)
}
@ -551,7 +551,7 @@ type Chained = C[Named] // B[Named, A[Named]] = B[Named, *Named] = []*Named
// Check that A is type A[T any] = *T.
// TODO(taking): fix how go/types prints parameterized aliases to simplify tests.
alias, ok := obj.Type().(*aliases.Alias)
alias, ok := obj.Type().(*types.Alias)
if !ok {
t.Fatalf("Obj %s is not an Alias", obj)
}

Просмотреть файл

@ -540,7 +540,7 @@ func canReuse(def *types.Named, rhs types.Type) bool {
if def == nil {
return true
}
iface, _ := aliases.Unalias(rhs).(*types.Interface)
iface, _ := types.Unalias(rhs).(*types.Interface)
if iface == nil {
return true
}
@ -615,7 +615,7 @@ func (r *importReader) obj(name string) {
if targs.Len() > 0 {
rparams = make([]*types.TypeParam, targs.Len())
for i := range rparams {
rparams[i] = aliases.Unalias(targs.At(i)).(*types.TypeParam)
rparams[i] = types.Unalias(targs.At(i)).(*types.TypeParam)
}
}
msig := r.signature(recv, rparams, nil)
@ -645,7 +645,7 @@ func (r *importReader) obj(name string) {
}
constraint := r.typ()
if implicit {
iface, _ := aliases.Unalias(constraint).(*types.Interface)
iface, _ := types.Unalias(constraint).(*types.Interface)
if iface == nil {
errorf("non-interface constraint marked implicit")
}
@ -852,7 +852,7 @@ func (r *importReader) typ() types.Type {
}
func isInterface(t types.Type) bool {
_, ok := aliases.Unalias(t).(*types.Interface)
_, ok := types.Unalias(t).(*types.Interface)
return ok
}
@ -1051,7 +1051,7 @@ func (r *importReader) tparamList() []*types.TypeParam {
for i := range xs {
// Note: the standard library importer is tolerant of nil types here,
// though would panic in SetTypeParams.
xs[i] = aliases.Unalias(r.typ()).(*types.TypeParam)
xs[i] = types.Unalias(r.typ()).(*types.TypeParam)
}
return xs
}

Просмотреть файл

@ -562,7 +562,7 @@ func (pr *pkgReader) objIdx(idx pkgbits.Index) (*types.Package, string) {
// If the underlying type is an interface, we need to
// duplicate its methods so we can replace the receiver
// parameter's type (#49906).
if iface, ok := aliases.Unalias(underlying).(*types.Interface); ok && iface.NumExplicitMethods() != 0 {
if iface, ok := types.Unalias(underlying).(*types.Interface); ok && iface.NumExplicitMethods() != 0 {
methods := make([]*types.Func, iface.NumExplicitMethods())
for i := range methods {
fn := iface.ExplicitMethod(i)

Просмотреть файл

@ -17,7 +17,6 @@ import (
"strings"
"golang.org/x/tools/go/types/typeutil"
"golang.org/x/tools/internal/aliases"
"golang.org/x/tools/internal/typeparams"
)
@ -423,7 +422,7 @@ func (st *falconState) expr(e ast.Expr) (res any) { // = types.TypeAndValue | as
if e.Type != nil {
_ = st.expr(e.Type)
}
t := aliases.Unalias(typeparams.Deref(tv.Type))
t := types.Unalias(typeparams.Deref(tv.Type))
var uniques []ast.Expr
for _, elt := range e.Elts {
if kv, ok := elt.(*ast.KeyValueExpr); ok {

Просмотреть файл

@ -16,8 +16,6 @@ import (
"go/ast"
"go/token"
"go/types"
"golang.org/x/tools/internal/aliases"
)
// UnpackIndexExpr extracts data from AST nodes that represent index
@ -65,7 +63,7 @@ func PackIndexExpr(x ast.Expr, lbrack token.Pos, indices []ast.Expr, rbrack toke
// IsTypeParam reports whether t is a type parameter (or an alias of one).
func IsTypeParam(t types.Type) bool {
_, ok := aliases.Unalias(t).(*types.TypeParam)
_, ok := types.Unalias(t).(*types.TypeParam)
return ok
}
@ -93,8 +91,8 @@ func IsTypeParam(t types.Type) bool {
// In this case, GenericAssignableTo reports that instantiations of Container
// are assignable to the corresponding instantiation of Interface.
func GenericAssignableTo(ctxt *types.Context, V, T types.Type) bool {
V = aliases.Unalias(V)
T = aliases.Unalias(T)
V = types.Unalias(V)
T = types.Unalias(T)
// If V and T are not both named, or do not have matching non-empty type
// parameter lists, fall back on types.AssignableTo.

Просмотреть файл

@ -6,8 +6,6 @@ package typeparams
import (
"go/types"
"golang.org/x/tools/internal/aliases"
)
// Free is a memoization of the set of free type parameters within a
@ -37,8 +35,8 @@ func (w *Free) Has(typ types.Type) (res bool) {
case nil, *types.Basic: // TODO(gri) should nil be handled here?
break
case *aliases.Alias:
return w.Has(aliases.Unalias(t))
case *types.Alias:
return w.Has(types.Unalias(t))
case *types.Array:
return w.Has(t.Elem())

Просмотреть файл

@ -12,7 +12,6 @@ import (
"strings"
"golang.org/x/tools/go/ast/inspector"
"golang.org/x/tools/internal/aliases"
)
// Features is a set of flags reporting which features of generic Go code a
@ -93,7 +92,7 @@ func ForPackage(inspect *inspector.Inspector, info *types.Info) Features {
})
for _, inst := range info.Instances {
switch aliases.Unalias(inst.Type).(type) {
switch types.Unalias(inst.Type).(type) {
case *types.Named:
direct |= TypeInstantiation
case *types.Signature:

Просмотреть файл

@ -9,7 +9,6 @@ import (
"go/types"
"golang.org/x/tools/go/types/typeutil"
"golang.org/x/tools/internal/aliases"
)
// ForEachElement calls f for type T and each type reachable from its
@ -67,8 +66,8 @@ func ForEachElement(rtypes *typeutil.Map, msets *typeutil.MethodSetCache, T type
}
switch T := T.(type) {
case *aliases.Alias:
visit(aliases.Unalias(T), skip) // emulates the pre-Alias behavior
case *types.Alias:
visit(types.Unalias(T), skip) // emulates the pre-Alias behavior
case *types.Basic:
// nop

Просмотреть файл

@ -13,7 +13,6 @@ import (
"testing"
"golang.org/x/tools/go/types/typeutil"
"golang.org/x/tools/internal/aliases"
"golang.org/x/tools/internal/typesinternal"
)
@ -102,7 +101,7 @@ func TestForEachElement(t *testing.T) {
t.Errorf("no such type %q", test.name)
continue
}
T := aliases.Unalias(tname.Type())
T := types.Unalias(tname.Type())
toStr := func(T types.Type) string {
return types.TypeString(T, func(*types.Package) string { return "" })

Просмотреть файл

@ -6,8 +6,6 @@ package typesinternal
import (
"go/types"
"golang.org/x/tools/internal/aliases"
)
// ReceiverNamed returns the named type (if any) associated with the
@ -15,11 +13,11 @@ import (
// It also reports whether a Pointer was present.
func ReceiverNamed(recv *types.Var) (isPtr bool, named *types.Named) {
t := recv.Type()
if ptr, ok := aliases.Unalias(t).(*types.Pointer); ok {
if ptr, ok := types.Unalias(t).(*types.Pointer); ok {
isPtr = true
t = ptr.Elem()
}
named, _ = aliases.Unalias(t).(*types.Named)
named, _ = types.Unalias(t).(*types.Named)
return
}
@ -36,7 +34,7 @@ func ReceiverNamed(recv *types.Var) (isPtr bool, named *types.Named) {
// indirection from the type, regardless of named types (analogous to
// a LOAD instruction).
func Unpointer(t types.Type) types.Type {
if ptr, ok := aliases.Unalias(t).(*types.Pointer); ok {
if ptr, ok := types.Unalias(t).(*types.Pointer); ok {
return ptr.Elem()
}
return t