Skip to content

Commit 46205df

Browse files
committed
Avoid counting control-scope err declarations as existing
1 parent 016685d commit 46205df

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

cmd/internal/migrations/v3/client_usage.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -615,6 +615,21 @@ func identifierDeclaredInLines(lines []string, name string) bool {
615615
continue
616616
}
617617

618+
// Declarations inside control statement initializers (e.g.,
619+
// "if err := ...") are scoped to that statement and should not be
620+
// treated as function-scope declarations.
621+
if strings.HasPrefix(trimmed, "if ") || strings.HasPrefix(trimmed, "for ") || strings.HasPrefix(trimmed, "switch ") || strings.HasPrefix(trimmed, "else if ") {
622+
if declaredInVarBlockLine(name, trimmed) {
623+
return true
624+
}
625+
626+
if name == defaultErrName && declaredInVarBlockLine("errs", trimmed) {
627+
return true
628+
}
629+
630+
continue
631+
}
632+
618633
if shortPattern.MatchString(trimmed) || varPattern.MatchString(trimmed) {
619634
return true
620635
}

0 commit comments

Comments
 (0)