4.5.3-1.3e 处理delayed队列
函数体的类型检查
type I interface {
m([unsafe.Sizeof(func() { I.m(nil) })]byte)
}循环依赖检查
type T T // 类型会无穷展开
type A struct {
self A // 递归引用,类型同样会无穷展开
}整理接口信息
其他情况
最后更新于
func (check *Checker) validType(typ Type, path []Object) typeInfo {
const (
unknown typeInfo = iota
marked
valid
invalid
)
switch t := typ.(type) {
case *Array:
return check.validType(t.elem, path)
case *Struct:
for _, f := range t.fields {
if check.validType(f.typ, path) == invalid {
return invalid
}
}
case *Interface:
for _, etyp := range t.embeddeds {
if check.validType(etyp, path) == invalid {
return invalid
}
}
case *Named:
switch t.info {
case unknown:
t.info = marked
t.info = check.validType(t.orig, append(path, t.obj))
case marked:
for i, tn := range path {
if tn == t.obj {
// 检测到循环依赖
check.cycleError(path[i:])
t.info = invalid
return t.info
}
}
panic("internal error: cycle start not found")
}
return t.info
case *instance:
return check.validType(t.expand(), path)
}
return valid
}type T *T
type A struct {
self *A
}