From 7db44ae3f9f309f635bcf16b187580c08b105ba9 Mon Sep 17 00:00:00 2001 From: Teddy Wing Date: Tue, 16 May 2023 01:49:59 +0200 Subject: Trying to get `types.Scope` of function literal Not working, as `funcObj` is nil. --- gocapturedrefrace.go | 13 +++++++++++++ 1 file changed, 13 insertions(+) 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) -- cgit v1.2.3