Skip to content

Commit

Permalink
Merge pull request #1698 from visualfc/typesutil_overloads
Browse files Browse the repository at this point in the history
use gox.CheckSigFuncExObjects
  • Loading branch information
xushiwei authored Feb 1, 2024
2 parents 936bcd7 + 4229eec commit b3dae2d
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 42 deletions.
30 changes: 9 additions & 21 deletions cl/expr.go
Original file line number Diff line number Diff line change
Expand Up @@ -504,32 +504,20 @@ func (p *fnType) load(fnt types.Type) {
case *gox.TypeType:
p.initTypeType(v)
case *types.Signature:
if typ, ok := gox.CheckFuncEx(v); ok {
switch t := typ.(type) {
case *gox.TyOverloadFunc:
p.initFuncs(0, t.Funcs...)
return
case *gox.TyOverloadMethod:
p.initFuncs(0, t.Methods...)
return
case *gox.TyTemplateRecvMethod:
if tsig, ok := t.Func.Type().(*types.Signature); ok {
if ex, ok := gox.CheckFuncEx(tsig); ok {
if t, ok := ex.(*gox.TyOverloadFunc); ok {
p.initFuncs(1, t.Funcs...)
return
}
}
}
p.initFuncs(1, t.Func)
return
}
typ, objs := gox.CheckSigFuncExObjects(v)
switch typ.(type) {
case *gox.TyOverloadFunc, *gox.TyOverloadMethod:
p.initFuncs(0, objs)
return
case *gox.TyTemplateRecvMethod:
p.initFuncs(1, objs)
return
}
p.init(0, v)
}
}

func (p *fnType) initFuncs(base int, funcs ...types.Object) {
func (p *fnType) initFuncs(base int, funcs []types.Object) {
for i, obj := range funcs {
if sig, ok := obj.Type().(*types.Signature); ok {
if i == 0 {
Expand Down
23 changes: 2 additions & 21 deletions x/typesutil/gopinfo.go
Original file line number Diff line number Diff line change
Expand Up @@ -244,30 +244,11 @@ func (info gopRecorder) Use(id *ast.Ident, obj types.Object) {
}
if info.Overloads != nil {
if sig, ok := obj.Type().(*types.Signature); ok {
if ext, ok := gox.CheckSigFuncEx(sig); ok {
if ext, objs := gox.CheckSigFuncExObjects(sig); len(objs) > 1 {
if debugVerbose {
log.Println("==> Overloads:", id, ext)
}
switch t := ext.(type) {
case *gox.TyOverloadFunc:
info.Overloads[id] = t.Funcs
case *gox.TyOverloadMethod:
info.Overloads[id] = t.Methods
case *gox.TyTemplateRecvMethod:
if tsig, ok := t.Func.Type().(*types.Signature); ok {
if ex, ok := gox.CheckSigFuncEx(tsig); ok {
if t, ok := ex.(*gox.TyOverloadFunc); ok {
info.Overloads[id] = t.Funcs
}
}
}
case *gox.TyOverloadNamed:
objs := make([]types.Object, len(t.Types))
for i, typ := range t.Types {
objs[i] = typ.Obj()
}
info.Overloads[id] = objs
}
info.Overloads[id] = objs
}
}
}
Expand Down

0 comments on commit b3dae2d

Please sign in to comment.