aboutsummaryrefslogtreecommitdiffstats
path: root/vendor/github.com/polyfloyd
diff options
context:
space:
mode:
authorTaras Madan <tarasmadan@google.com>2023-12-05 15:10:03 +0100
committerTaras Madan <tarasmadan@google.com>2023-12-06 11:31:44 +0000
commit2ab72b4feef2c97f22f90cfbf9e45a6cfcd08bda (patch)
treea6d19b94b6399fcc00a6cfa430885cd349dd1533 /vendor/github.com/polyfloyd
parente08e8f492d31d672cc245944c185f8aadf2ee695 (diff)
vendor: updates
Diffstat (limited to 'vendor/github.com/polyfloyd')
-rw-r--r--vendor/github.com/polyfloyd/go-errorlint/errorlint/allowed.go19
1 files changed, 13 insertions, 6 deletions
diff --git a/vendor/github.com/polyfloyd/go-errorlint/errorlint/allowed.go b/vendor/github.com/polyfloyd/go-errorlint/errorlint/allowed.go
index be4debf9b..df8d5f713 100644
--- a/vendor/github.com/polyfloyd/go-errorlint/errorlint/allowed.go
+++ b/vendor/github.com/polyfloyd/go-errorlint/errorlint/allowed.go
@@ -3,6 +3,7 @@ package errorlint
import (
"fmt"
"go/ast"
+ "go/types"
"strings"
)
@@ -110,7 +111,7 @@ func isAllowedErrorComparison(pass *TypesInfoExt, binExpr *ast.BinaryExpr) bool
case *ast.Ident:
// Identifier, most likely to be the `err` variable or whatever
// produces it.
- callExprs = assigningCallExprs(pass, t)
+ callExprs = assigningCallExprs(pass, t, map[types.Object]bool{})
case *ast.CallExpr:
callExprs = append(callExprs, t)
}
@@ -149,15 +150,21 @@ func isAllowedErrorComparison(pass *TypesInfoExt, binExpr *ast.BinaryExpr) bool
// assigningCallExprs finds all *ast.CallExpr nodes that are part of an
// *ast.AssignStmt that assign to the subject identifier.
-func assigningCallExprs(pass *TypesInfoExt, subject *ast.Ident) []*ast.CallExpr {
+func assigningCallExprs(pass *TypesInfoExt, subject *ast.Ident, visitedObjects map[types.Object]bool) []*ast.CallExpr {
if subject.Obj == nil {
return nil
}
- // Find other identifiers that reference this same object. Make sure to
- // exclude the subject identifier as it will cause an infinite recursion
- // and is being used in a read operation anyway.
+ // Find other identifiers that reference this same object.
sobj := pass.TypesInfo.ObjectOf(subject)
+
+ if visitedObjects[sobj] {
+ return nil
+ }
+ visitedObjects[sobj] = true
+
+ // Make sure to exclude the subject identifier as it will cause an infinite recursion and is
+ // being used in a read operation anyway.
identifiers := []*ast.Ident{}
for _, ident := range pass.IdentifiersForObject[sobj] {
if subject.Pos() != ident.Pos() {
@@ -196,7 +203,7 @@ func assigningCallExprs(pass *TypesInfoExt, subject *ast.Ident) []*ast.CallExpr
continue
}
// The subject was the result of assigning from another identifier.
- callExprs = append(callExprs, assigningCallExprs(pass, assignT)...)
+ callExprs = append(callExprs, assigningCallExprs(pass, assignT, visitedObjects)...)
default:
// TODO: inconclusive?
}