aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTeddy Wing2023-05-21 14:53:34 +0200
committerTeddy Wing2023-05-21 14:53:34 +0200
commit9e99cd0a6f42a7f7ceba89884d231eaf386a08f6 (patch)
tree75dcd7705dcacc0305e8ca8a7613746704eeeb3e
parente8fd6345dd1cbd16ee518e6b5ff6e10fb2b52931 (diff)
downloadgodefererr-9e99cd0a6f42a7f7ceba89884d231eaf386a08f6.tar.bz2
Working out why doesDeclareErrInSignature doesn't get far in assign loop
We were looking for a `*ast.ValueSpec`, but it looks like when `err` is declared in the function signature, the type is `*ast.Field`.
-rw-r--r--defererr.go16
1 files changed, 10 insertions, 6 deletions
diff --git a/defererr.go b/defererr.go
index 77a872d..13008a2 100644
--- a/defererr.go
+++ b/defererr.go
@@ -199,19 +199,23 @@ func checkErrorAssignedInDefer(
continue
}
+ // TODO: Figure out why doesDeclareErrInSignature doesn't
+ // continue past here.
+ fmt.Printf("variable: %#v\n", ident)
+ fmt.Printf("variable.obj: %#v\n", ident.Obj)
+ fmt.Printf("variable.obj.type: %#v\n", ident.Obj.Type)
+ fmt.Printf("variable.obj.decl: %#v\n", ident.Obj.Decl)
+
obj := pass.TypesInfo.Defs[ident]
+ fmt.Printf("obj: %#v\n", obj)
valueSpec, ok := ident.Obj.Decl.(*ast.ValueSpec)
if !ok {
continue
}
- fmt.Printf("variable: %#v\n", ident)
- fmt.Printf("variable.obj: %#v\n", ident.Obj)
- fmt.Printf("variable.obj.type: %#v\n", ident.Obj.Type)
fmt.Printf("variable.obj.valuespec: %#v\n", valueSpec)
fmt.Printf("variable.obj.valuespec.type: %#v\n", valueSpec.Type)
- fmt.Printf("obj: %#v\n", obj)
t := pass.TypesInfo.Types[variable]
fmt.Printf("type: %#v\n", t)
@@ -243,8 +247,6 @@ func checkErrorAssignedInDefer(
}
}
- fState.setFirstErrorDeferEndPos(deferFuncLit.Body.Rbrace)
-
// Maybe don't report the error if it was declared in the closure using a GenDecl? -> We already don't. Should test for these things.
if !isErrorNameInReturnSignature {
@@ -265,6 +267,8 @@ func checkErrorAssignedInDefer(
return true
}
+ fState.setFirstErrorDeferEndPos(deferFuncLit.Body.Rbrace)
+
// TODO: Check that funcDecl declares error in signature (check before ast.Inspect on function body, report here)
// isErrorNameInReturnSignature := false