Closed
Description
(using #43698 as a template)
Related issues: #9926, #35239
Per the Go specification of for loops, within the For statements with range clause section, it states:
If a map entry is created during iteration, that entry may be produced during the iteration or may be skipped. The choice may vary for each entry created and from one iteration to the next.
I expect that package authors might not be expecting the non-deterministic behavior that comes with concurrent modification. This can lead to unexpected bugs and behavior. I believe Java goes so far to even throw a runtime exception.
Playground example
Real-world example
I propose that cmd/vet
should emit a warning when:
- a map is iterated over using a for statement
- the map has elements added during iteration