From ba68300918317cf93bc08b68427159d1d2371a86 Mon Sep 17 00:00:00 2001 From: zhouyusd <1848611319@qq.com> Date: Sun, 5 Oct 2025 16:54:11 +0800 Subject: [PATCH 1/2] feat: enhance type handling for index expressions and add generic type support --- internal/parser/parser.go | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/internal/parser/parser.go b/internal/parser/parser.go index 5c4cdda0..5402c995 100644 --- a/internal/parser/parser.go +++ b/internal/parser/parser.go @@ -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) } @@ -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: From a5fd3a3f2bcb1d5abd1d8728cc0ee068038fb54d Mon Sep 17 00:00:00 2001 From: Tao Yu <71547744+zhouyusd@users.noreply.github.com> Date: Sun, 5 Oct 2025 17:18:52 +0800 Subject: [PATCH 2/2] fix: add fallback for unsupported types in type handling Co-authored-by: propel-code-bot[bot] <203372662+propel-code-bot[bot]@users.noreply.github.com> --- internal/parser/parser.go | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/internal/parser/parser.go b/internal/parser/parser.go index 5402c995..e12ba41e 100644 --- a/internal/parser/parser.go +++ b/internal/parser/parser.go @@ -322,7 +322,11 @@ func (p *Param) astGetGenericType(exprList ...ast.Expr) { } var types []string for _, expr := range exprList { - types = append(types, astGetType(expr)) + typeStr := astGetType(expr) + if typeStr == "" { + typeStr = "interface{}" // fallback for unsupported types + } + types = append(types, typeStr) } p.Type = fmt.Sprintf("%s[%s]", p.Type, strings.Join(types, ", ")) }