-
Notifications
You must be signed in to change notification settings - Fork 18.4k
Closed
Labels
AnalysisIssues related to static analysis (vet, x/tools/go/analysis)Issues related to static analysis (vet, x/tools/go/analysis)FrozenDueToAgeLanguageChangeSuggested changes to the Go languageSuggested changes to the Go languageNeedsDecisionFeedback is required from experts, contributors, and/or the community before a change can be made.Feedback is required from experts, contributors, and/or the community before a change can be made.Proposalv2An incompatible library changeAn incompatible library change
Milestone
Description
As an alternative to #20725 (which was originally about go vet), let the variables of range loops be implicitly redefined in each iteration like in Dart's for
loops. That is,
for k, v := range vals {
// ...
}
should be equivalent to
for k, v := range vals {
k := k
v := v
// ...
}
This will make it "safe" to take the loop variable's addresses as well as capturing the loop variables in nested functions (see #16520).
The proposal could be expanded to vanilla for
loops, although that would make it diverge semantically from other languages.
dsnet, zegl, mrd0ll4r, avdva, pwaller and 191 morecznic, as, HenrikSolver, quillaja, kortschak and 3 morebcmills, qiukeren, dsnet, hooluupog, peppelan and 14 moreHeimdell, Seklfreak, nightlyone, anjmao, ericlagergren and 13 more
Metadata
Metadata
Assignees
Labels
AnalysisIssues related to static analysis (vet, x/tools/go/analysis)Issues related to static analysis (vet, x/tools/go/analysis)FrozenDueToAgeLanguageChangeSuggested changes to the Go languageSuggested changes to the Go languageNeedsDecisionFeedback is required from experts, contributors, and/or the community before a change can be made.Feedback is required from experts, contributors, and/or the community before a change can be made.Proposalv2An incompatible library changeAn incompatible library change