From 3442d134b4a66ecc198da08151fdd2cfea3aad4e Mon Sep 17 00:00:00 2001 From: Teddy Wing Date: Tue, 16 May 2023 01:09:40 +0200 Subject: Use `pass.TypesInfo.Defs[ident]` to differentiate DEFINE/ASSIGN Got this idea from a question by zhizhixiong (https://stackoverflow.com/users/12073516/zhizhixiong) on Stack Overflow: https://stackoverflow.com/questions/66544145/how-to-find-the-declaration-of-an-ident-using-go-analysis This seems to correctly print defines and assigns. It doesn't print the `decl` variable though. --- gocapturedrefrace.go | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/gocapturedrefrace.go b/gocapturedrefrace.go index 0ca4af7..d88989e 100644 --- a/gocapturedrefrace.go +++ b/gocapturedrefrace.go @@ -160,6 +160,12 @@ func assignmentsInFunc( fmt.Printf("assignment: %v\n", assignment.Tok) } + if pass.TypesInfo.Defs[ident] != nil { + fmt.Println("DEFINE:", ident) + } else { + fmt.Println("ASSIGN:", ident) + } + assignments = append(assignments, ident.Name) return true -- cgit v1.2.3