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

No check for unnecessary nil check on a map followed by a len check of the same map #1527

Open
ChrisHines opened this issue Apr 24, 2024 · 0 comments

Comments

@ChrisHines
Copy link

Considering staticcheck identifies unnecessary nil checks for slices followed by a len check, I am surprised it doesn’t seem to do the same for maps.

I was just reviewing some code that is essentially:

type obj struct {
    m map[uint64]bool
}

func (o *obj) method() {
    if o.m != nil && len(o.m) > 0 {
        // start goroutine to process elements of `o.m`
    }
}

I was expecting staticcheck to flag the o.m != nil part as unnecessary, but it isn’t.

@ChrisHines ChrisHines added the needs-triage Newly filed issue that needs triage label Apr 24, 2024
@dominikh dominikh added enhancement and removed needs-triage Newly filed issue that needs triage labels Apr 24, 2024
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