Skip to content

Commit 528790c

Browse files
committed
check result type of methods
1 parent 7e88f4d commit 528790c

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

tool/xgen/parser/parser.go

+6-1
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,13 @@ func (v *visitor) Visit(n ast.Node) (w ast.Visitor) {
5757
return nil
5858
case *ast.FuncDecl:
5959
if isExported(v.name) {
60-
if n.Type.Params.NumFields() == 3 {
60+
if n.Type.Params.NumFields() == 3 && n.Type.Results.NumFields() == 1 {
6161
params := n.Type.Params.List
62+
result := n.Type.Results.List[0]
63+
64+
if result.Type.(*ast.Ident).Name != "error" {
65+
return nil
66+
}
6267

6368
if p, ok := params[0].Type.(*ast.SelectorExpr); ok {
6469
x := p.X.(*ast.Ident)

tool/xgen/xgen.go

+7
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,13 @@ func main() {
4848
panic(err)
4949
}
5050

51+
if !filepath.IsAbs(fname) {
52+
fname, err = filepath.Abs(fname)
53+
if err != nil {
54+
panic(err)
55+
}
56+
}
57+
5158
relDir, err := filepath.Rel(filepath.Join(build.Default.GOPATH, "src"), fname)
5259
if err != nil {
5360
fmt.Printf("provided directory not under GOPATH (%s): %v",

0 commit comments

Comments
 (0)