Skip to content
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions internal/parser/parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -273,8 +273,10 @@ func (p *Param) astGetParamType(param *ast.Field) {
p.astGetEltType(v.X)
case *ast.IndexExpr:
p.astGetEltType(v.X)
p.astGetGenericType(v.Index)
case *ast.IndexListExpr:
p.astGetEltType(v.X)
p.astGetGenericType(v.Indices...)
default:
log.Printf("Unsupported param type: %+v", v)
}
Expand Down Expand Up @@ -302,11 +304,29 @@ func (p *Param) astGetEltType(expr ast.Expr) {
p.Type = "[]" + p.Type
case *ast.IndexExpr:
p.astGetEltType(v.X)
p.astGetGenericType(v.Index)
case *ast.IndexListExpr:
p.astGetEltType(v.X)
p.astGetGenericType(v.Indices...)
default:
log.Printf("Unsupported param type: %+v", v)
}
}

func (p *Param) astGetGenericType(exprList ...ast.Expr) {
if p.Package == "" {
p.Package = "UNDEFINED" // Generic types are definitely not built-in types.
}
if len(exprList) == 0 {
return
}
var types []string
for _, expr := range exprList {
types = append(types, astGetType(expr))
}
p.Type = fmt.Sprintf("%s[%s]", p.Type, strings.Join(types, ", "))
}

func (p *Param) astGetPackageName(expr ast.Expr) {
switch v := expr.(type) {
case *ast.Ident:
Expand Down
Loading