Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

False positive with range-over-function #29

Open
jdemeyer opened this issue Aug 28, 2024 · 0 comments
Open

False positive with range-over-function #29

jdemeyer opened this issue Aug 28, 2024 · 0 comments

Comments

@jdemeyer
Copy link

The prealloc code seems to assume that the length of whatever you are iterating over is known in advance. But this is no longer true with the new Go 1.23 range-over-function iterators.

Minimal example:

package main

func iterator(func(int) bool) {
    // ...iterator implementation...
}

func main() {
    var slice []int
    for i := range iterator {
        slice = append(slice, i)
    }
}

Solution: do not issue a linter warning for range-over-function loops.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants