From 9993783a0d2fc7e087e6370288ed191cfa292a9f Mon Sep 17 00:00:00 2001 From: Teddy Wing Date: Thu, 18 May 2023 22:23:50 +0200 Subject: Use `FuncDecl` instead of `FuncType` I didn't read the docs carefully, it turns out `FuncType` only gives us the signature. If we want access to the function body as well to be able to walk its AST, we need a `FuncDecl`. --- defererr.go | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'defererr.go') diff --git a/defererr.go b/defererr.go index fafb42e..ae5f688 100644 --- a/defererr.go +++ b/defererr.go @@ -24,17 +24,17 @@ func run(pass *analysis.Pass) (interface{}, error) { ast.Inspect( file, func(node ast.Node) bool { - funcType, ok := node.(*ast.FuncType) + funcDecl, ok := node.(*ast.FuncDecl) if !ok { return true } - if funcType.Results == nil { + if funcDecl.Type.Results == nil { return true } funcReturnsError := false - for _, returnVal := range funcType.Results.List { + for _, returnVal := range funcDecl.Type.Results.List { fmt.Printf("returnVal: %#v\n", returnVal.Type) returnIdent, ok := returnVal.Type.(*ast.Ident) @@ -56,9 +56,9 @@ func run(pass *analysis.Pass) (interface{}, error) { } ast.Inspect( - funcType, + funcDecl.Body, func(node ast.Node) bool { - fmt.Printf("node: %#v\n", node) + // fmt.Printf("node: %#v\n", node) deferStmt, ok := node.(*ast.DeferStmt) if !ok { return true -- cgit v1.2.3