Skip to content

Commit

Permalink
Merge pull request #208 from goplus/typeargs
Browse files Browse the repository at this point in the history
TypesRecord: fix parse func type args
  • Loading branch information
visualfc committed Feb 2, 2023
2 parents 7e24119 + 94d3ac6 commit c4dbedc
Showing 1 changed file with 5 additions and 10 deletions.
15 changes: 5 additions & 10 deletions types_go118.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import (
"strconv"
"strings"

"github.com/goplus/reflectx"
"golang.org/x/tools/go/ssa"
"golang.org/x/tools/go/types/typeutil"
)
Expand Down Expand Up @@ -69,25 +68,21 @@ func (r *TypesRecord) typeId(typ types.Type, t reflect.Type) string {
}

func (r *TypesRecord) EnterInstance(fn *ssa.Function) {
r.fntargs = ""
r.fntargs = r.parseFuncTypeArgs(fn)
r.ncache = r.nstack.Push(r.fntargs)
r.fntargs = r.parseFuncTypeArgs(fn)
}

func (r *TypesRecord) LeaveInstance(fn *ssa.Function) {
r.fntargs, r.ncache = r.nstack.Pop()
}

func (r *TypesRecord) parseFuncTypeArgs(fn *ssa.Function) (targs string) {
name := fn.Name()
pos := strings.Index(name, "[")
if pos < 0 {
return ""
typeargs := fn.TypeArgs()
if len(typeargs) == 0 {
return
}
v := reflectx.FieldByNameX(reflect.ValueOf(fn).Elem(), "typeargs")
var args []string
for i := 0; i < v.Len(); i++ {
typ := v.Index(i).Interface().(types.Type)
for _, typ := range typeargs {
rt, _ := r.ToType(typ)
args = append(args, r.typeId(typ, rt))
}
Expand Down

0 comments on commit c4dbedc

Please sign in to comment.