1 // Copyright 2023 The Go Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style
3 // license that can be found in the LICENSE file.
9 // Names starting with a _ are intended to be exported eventually
10 // (go.dev/issue/63223).
12 // An _Alias represents an alias type.
14 obj *TypeName // corresponding declared alias object
15 fromRHS Type // RHS of type alias declaration; may be an alias
16 actual Type // actual (aliased) type; never an alias
19 // _NewAlias creates a new Alias type with the given type name and rhs.
20 // rhs must not be nil.
21 func _NewAlias(obj *TypeName, rhs Type) *_Alias {
22 return (*Checker)(nil).newAlias(obj, rhs)
25 func (a *_Alias) Underlying() Type { return a.actual.Underlying() }
26 func (a *_Alias) String() string { return TypeString(a, nil) }
30 // _Unalias returns t if it is not an alias type;
31 // otherwise it follows t's alias chain until it
32 // reaches a non-alias type which is then returned.
33 // Consequently, the result is never an alias type.
34 func _Unalias(t Type) Type {
35 if a0, _ := t.(*_Alias); a0 != nil {
47 panic(fmt.Sprintf("non-terminated alias %s", a0.obj.name))
54 // asNamed returns t as *Named if that is t's
55 // actual type. It returns nil otherwise.
56 func asNamed(t Type) *Named {
57 n, _ := _Unalias(t).(*Named)
61 // newAlias creates a new Alias type with the given type name and rhs.
62 // rhs must not be nil.
63 func (check *Checker) newAlias(obj *TypeName, rhs Type) *_Alias {
65 a := &_Alias{obj, rhs, nil}
70 // Ensure that a.actual is set at the end of type checking.
78 func (a *_Alias) cleanup() {