4.4.4-7 Named 类型
Named 结构用来表示 Defined Types, 即通过语法结构type A β
或者type A = β
定义的类型,其中 β 表示任何合法的表达式,例如如果 β 表示struct {...}
, 则整个声明就是一个 struct 结构体。
Named结构定义如下:
type Named struct {
check *Checker // for Named.under implementation
info typeInfo
obj *TypeName // corresponding declared object
orig Type // type (on RHS of declaration) this *Named type is derived of (for cycle reporting)
underlying Type // possibly a *Named during setup; never a *Named once set up completely
tparams []*TypeName // 类型参数名字,用于泛型
targs []Type // 类型参数的限定类型(constraint)
methods []*Func // 与该类型绑定的方法
}
check 是类型检查器的数据结构,详细介绍在Checker, 字段info
在后期用于类型的循环依赖检查. 每种类型都必须实现Underlying() Type
方法(见Type 接口),其他所有类型的该方法都是返回自身,只有 Named 类型是返回属性underlying
.
最后更新于
这有帮助吗?