diff options
| author | Teddy Wing | 2023-05-16 01:49:59 +0200 | 
|---|---|---|
| committer | Teddy Wing | 2023-05-16 01:49:59 +0200 | 
| commit | 7db44ae3f9f309f635bcf16b187580c08b105ba9 (patch) | |
| tree | eac425079261d464ade21394d1452a0af845c640 | |
| parent | f439b3e8dffb04ecd4ede0a4b32ceb9f6bec0621 (diff) | |
| download | gocapturedrefrace-7db44ae3f9f309f635bcf16b187580c08b105ba9.tar.bz2 | |
Trying to get `types.Scope` of function literal
Not working, as `funcObj` is nil.
| -rw-r--r-- | gocapturedrefrace.go | 13 | 
1 files changed, 13 insertions, 0 deletions
| diff --git a/gocapturedrefrace.go b/gocapturedrefrace.go index 483bd7f..dfa32aa 100644 --- a/gocapturedrefrace.go +++ b/gocapturedrefrace.go @@ -35,6 +35,19 @@ func run(pass *analysis.Pass) (interface{}, error) {  				fmt.Printf("%#v\n", goStmt) +				funcIdent, ok := goStmt.Call.Fun.(*ast.Ident) +				funcObj := pass.TypesInfo.ObjectOf(funcIdent) +				if funcObj != nil { +					theFunc, ok := funcObj.(*types.Func) +					if ok { +						fmt.Printf("func scope: %#v\n", theFunc.Scope()) +					} else { +						fmt.Println("func scope: error") +					} +				} else { +					fmt.Println("funcObj: error") +				} +  				// TODO: Get func literal of go statement  				// TODO: Get variables in func literal  				funcLit, ok := goStmt.Call.Fun.(*ast.FuncLit) | 
