aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTeddy Wing2023-05-18 01:46:16 +0200
committerTeddy Wing2023-05-18 01:46:16 +0200
commitace55a2a1696e3b60891b5d731705ead72446f7d (patch)
tree3c13a702fab6c4d4e901e90ce462e89ce6abf1c3
parent0fddc640af772014e5a87db394657f03e273c528 (diff)
downloadgocapturedrefrace-ace55a2a1696e3b60891b5d731705ead72446f7d.tar.bz2
Try to ignore shadowed assignments
Not working yet. Does print the right thing, but since we're also matching `*ast.Ident`s, we must be getting the shadowed declarations as Idents and including them in the reported diagnostics.
-rw-r--r--gocapturedrefrace.go24
1 files changed, 15 insertions, 9 deletions
diff --git a/gocapturedrefrace.go b/gocapturedrefrace.go
index d5eaac7..369b107 100644
--- a/gocapturedrefrace.go
+++ b/gocapturedrefrace.go
@@ -87,7 +87,9 @@ func checkClosure(pass *analysis.Pass, funcLit *ast.FuncLit) {
ast.Inspect(
funcLit,
func(node ast.Node) bool {
- checkShadowing(pass, node, funcScope)
+ if isShadowingDeclaration(pass, node, funcScope) {
+ return true
+ }
ident, ok := node.(*ast.Ident)
if !ok {
@@ -137,37 +139,41 @@ func checkClosure(pass *analysis.Pass, funcLit *ast.FuncLit) {
}
// TODO: doc
-func checkShadowing(
+func isShadowingDeclaration(
pass *analysis.Pass,
node ast.Node,
funcScope *types.Scope,
-) {
+) bool {
assignStmt, ok := node.(*ast.AssignStmt)
if !ok {
- return
+ return false
}
if assignStmt.Tok != token.DEFINE {
- return
+ return false
}
for _, lhs := range assignStmt.Lhs {
ident, ok := lhs.(*ast.Ident)
if !ok {
- return
+ return false
}
fmt.Printf("assignStmt: %#v\n", ident)
- if ident != nil {
- return
+ if ident == nil {
+ return false
}
+ return true
+
// TODO: If ident is in parent, ignore it an move on.
// scope, scopeObj := funcScope.LookupParent(ident.Name, ident.NamePos)
- //
+ //
// // Identifier is local to the closure.
// if scope == nil && scopeObj == nil {
// return
// }
}
+
+ return false
}