aboutsummaryrefslogtreecommitdiffstats
path: root/defererr.go
diff options
context:
space:
mode:
authorTeddy Wing2023-05-21 01:09:37 +0200
committerTeddy Wing2023-05-21 01:09:37 +0200
commita7d7125608b4a823aa377be9cc11c6078628fb39 (patch)
treea94c035d0256e3ff2d4e85f074407fc0e5de3d7d /defererr.go
parente52023c71df80dd8645a6fab8abdbfdf6c2d4355 (diff)
downloadgodefererr-a7d7125608b4a823aa377be9cc11c6078628fb39.tar.bz2
Ignore errors declared using GenDecl inside defer closure
We don't want to report error variables that were declared inside the closure, as those don't depend on the outside scope.
Diffstat (limited to 'defererr.go')
-rw-r--r--defererr.go8
1 files changed, 8 insertions, 0 deletions
diff --git a/defererr.go b/defererr.go
index e4e0ebe..71a9d15 100644
--- a/defererr.go
+++ b/defererr.go
@@ -183,6 +183,14 @@ func checkErrorAssignedInDefer(
fmt.Printf("type.type.obj: %#v\n", named.Obj())
fmt.Printf("type.type.obj: %#v\n", named.Obj().Name())
+ // TODO: Was error lhs declared in defer closure? Then it
+ // should be ignored.
+ if deferFuncLit.Body.Lbrace < valueSpec.Pos() &&
+ valueSpec.Pos() < deferFuncLit.Body.Rbrace {
+
+ continue
+ }
+
if named.Obj().Name() == "error" {
deferAssignsError = true