You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Extend the copylock analyzer to emit a warning on the copy of the loop variable between iterations that occurs immediately before the loop's Post statement in Go >= 1.22. The requirements for the warning are when:
a 3-clause for loop declares a loop scoped variable containing a lock type,
the file's GoVersion is >= 1.22,
the name of the variable is not _, and
the Init statement of the for loop is not otherwise reported.
Example:
for _, mu := 0, (sync.Mutex{}); x < 10; x++ { // want "for loop iteration copies lock value to mu: sync.Mutex"
_ = mu.TryLock()
}
The variable used by each subsequent iteration is declared implicitly before executing the post statement and initialized to the value of the previous iteration's variable at that moment.
The text was updated successfully, but these errors were encountered:
timothy-king
changed the title
cmd/vet: warn on 3-clause loops where an iterator variable contains a lock type when GoVersion>1.22
cmd/vet: warn on 3-clause loops where an iterator variable contains a lock type when GoVersion>=1.22
Mar 18, 2024
ianlancetaylor
changed the title
cmd/vet: warn on 3-clause loops where an iterator variable contains a lock type when GoVersion>=1.22
proposal: cmd/vet: warn on 3-clause loops where an iterator variable contains a lock type when GoVersion>=1.22
Mar 27, 2024
Proposal Details
Extend the
copylock
analyzer to emit a warning on the copy of the loop variable between iterations that occurs immediately before the loop's Post statement in Go >= 1.22. The requirements for the warning are when:_
, andExample:
Relevant part of the spec https://go.dev/ref/spec#For_clause :
The text was updated successfully, but these errors were encountered: