Skip to content

Commit 8435743

Browse files
committed
find error type in types.Universe
1 parent 62d28d1 commit 8435743

File tree

1 file changed

+5
-6
lines changed

1 file changed

+5
-6
lines changed

analyzer/analyzer.go

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ func flags() flag.FlagSet {
2828

2929
func run(pass *analysis.Pass) (interface{}, error) {
3030
allowErrorInDefer := pass.Analyzer.Flags.Lookup(FlagAllowErrorInDefer).Value.String() == "true"
31+
errorType := types.Universe.Lookup("error").Type()
3132

3233
inspector := pass.ResultOf[inspect.Analyzer].(*inspector.Inspector)
3334

@@ -70,12 +71,10 @@ func run(pass *analysis.Pass) (interface{}, error) {
7071
continue
7172
}
7273

73-
if allowErrorInDefer {
74-
if pass.TypesInfo.TypeOf(p.Type).String() == "error" { // with package prefix, so only built-it error fits
75-
if findDeferWithVariableAssignment(funcBody, pass.TypesInfo, pass.TypesInfo.ObjectOf(n)) {
76-
continue
77-
}
78-
}
74+
if allowErrorInDefer &&
75+
types.Identical(pass.TypesInfo.TypeOf(p.Type), errorType) &&
76+
findDeferWithVariableAssignment(funcBody, pass.TypesInfo, pass.TypesInfo.ObjectOf(n)) {
77+
continue
7978
}
8079

8180
pass.Reportf(node.Pos(), "named return %q with type %q found", n.Name, types.ExprString(p.Type))

0 commit comments

Comments
 (0)