diff options
| author | Teddy Wing | 2023-05-18 22:23:50 +0200 | 
|---|---|---|
| committer | Teddy Wing | 2023-05-18 22:23:50 +0200 | 
| commit | 9993783a0d2fc7e087e6370288ed191cfa292a9f (patch) | |
| tree | 25dbda318de21b80c73eb5272969c4f7844549c8 | |
| parent | 046e10da6483d05a0b16bea75baf8effa57a056d (diff) | |
| download | godefererr-9993783a0d2fc7e087e6370288ed191cfa292a9f.tar.bz2 | |
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`.
| -rw-r--r-- | defererr.go | 10 | 
1 files changed, 5 insertions, 5 deletions
| 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 | 
