if t1 == nil || t2 == nil || t1.kind != t2.kind {
return false
}
- if t1.sym != nil || t2.sym != nil {
+ if t1.obj != nil || t2.obj != nil {
if flags&identStrict == 0 && (t1.HasShape() || t2.HasShape()) {
switch t1.kind {
case TINT8, TUINT8, TINT16, TUINT16, TINT32, TUINT32, TINT64, TUINT64, TINT, TUINT, TUINTPTR, TCOMPLEX64, TCOMPLEX128, TFLOAT32, TFLOAT64, TBOOL, TSTRING, TPTR, TUNSAFEPTR:
allMethods Fields
// canonical OTYPE node for a named type (should be an ir.Name node with same sym)
- nod Object
+ obj Object
// the underlying type (type literal or predeclared type) for a defined type
underlying *Type
slice *Type // []T, or nil
}
- sym *Sym // symbol containing name, for named types
vargen int32 // unique name for OTYPE/ONAME
kind Kind // kind of type
func (t *Type) Kind() Kind { return t.kind }
// Sym returns the name of type t.
-func (t *Type) Sym() *Sym { return t.sym }
+func (t *Type) Sym() *Sym {
+ if t.obj != nil {
+ return t.obj.Sym()
+ }
+ return nil
+}
// OrigType returns the original generic type that t is an
// instantiation of, if any.
// Pos returns a position associated with t, if any.
// This should only be used for diagnostics.
func (t *Type) Pos() src.XPos {
- if t.nod != nil {
- return t.nod.Pos()
+ if t.obj != nil {
+ return t.obj.Pos()
}
return src.NoXPos
}
return cmpForNe(t.kind < x.kind)
}
- if t.sym != nil || x.sym != nil {
+ if t.obj != nil || x.obj != nil {
// Special case: we keep byte and uint8 separate
// for error messages. Treat them as equal.
switch t.kind {
}
}
- if c := t.sym.cmpsym(x.sym); c != CMPeq {
+ if c := t.Sym().cmpsym(x.Sym()); c != CMPeq {
return c
}
- if x.sym != nil {
+ if x.obj != nil {
// Syms non-nil, if vargens match then equal.
if t.vargen != x.vargen {
return cmpForNe(t.vargen < x.vargen)
// the type is complete.
func NewNamed(obj Object) *Type {
t := newType(TFORW)
- t.sym = obj.Sym()
- t.nod = obj
- if t.sym.Pkg == ShapePkg {
+ t.obj = obj
+ if obj.Sym().Pkg == ShapePkg {
t.SetIsShape(true)
t.SetHasShape(true)
}
// Obj returns the canonical type name node for a named type t, nil for an unnamed type.
func (t *Type) Obj() Object {
- if t.sym != nil {
- return t.nod
- }
- return nil
+ return t.obj
}
// typeGen tracks the number of function-scoped defined types that
// NewBasic returns a new basic type of the given kind.
func newBasic(kind Kind, obj Object) *Type {
t := newType(kind)
- t.sym = obj.Sym()
- t.nod = obj
+ t.obj = obj
return t
}
// and specified index within the typeparam list.
func NewTypeParam(obj Object, index int) *Type {
t := newType(TTYPEPARAM)
- t.sym = obj.Sym()
- t.nod = obj
+ t.obj = obj
t.extra.(*Typeparam).index = index
t.SetHasTParam(true)
return t