1 // Code generated by "go test -run=Generate -write=all"; DO NOT EDIT.
3 // Copyright 2023 The Go Authors. All rights reserved.
4 // Use of this source code is governed by a BSD-style
5 // license that can be found in the LICENSE file.
11 // An Alias represents an alias type.
12 // Whether or not Alias types are created is controlled by the
13 // gotypesalias setting with the GODEBUG environment variable.
14 // For gotypesalias=1, alias declarations produce an Alias type.
15 // Otherwise, the alias information is only in the type name,
16 // which points directly to the actual (aliased) type.
18 obj *TypeName // corresponding declared alias object
19 fromRHS Type // RHS of type alias declaration; may be an alias
20 actual Type // actual (aliased) type; never an alias
23 // NewAlias creates a new Alias type with the given type name and rhs.
24 // rhs must not be nil.
25 func NewAlias(obj *TypeName, rhs Type) *Alias {
26 return (*Checker)(nil).newAlias(obj, rhs)
29 func (a *Alias) Obj() *TypeName { return a.obj }
30 func (a *Alias) Underlying() Type { return a.actual.Underlying() }
31 func (a *Alias) String() string { return TypeString(a, nil) }
35 // Unalias returns t if it is not an alias type;
36 // otherwise it follows t's alias chain until it
37 // reaches a non-alias type which is then returned.
38 // Consequently, the result is never an alias type.
39 func Unalias(t Type) Type {
40 if a0, _ := t.(*Alias); a0 != nil {
52 panic(fmt.Sprintf("non-terminated alias %s", a0.obj.name))
59 // asNamed returns t as *Named if that is t's
60 // actual type. It returns nil otherwise.
61 func asNamed(t Type) *Named {
62 n, _ := Unalias(t).(*Named)
66 // newAlias creates a new Alias type with the given type name and rhs.
67 // rhs must not be nil.
68 func (check *Checker) newAlias(obj *TypeName, rhs Type) *Alias {
70 a := &Alias{obj, rhs, nil}
75 // Ensure that a.actual is set at the end of type checking.
83 func (a *Alias) cleanup() {