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

Closed
ChrisHines opened this issue Apr 24, 2024 · 1 comment

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
arp242 added a commit to arp242/go-tools that referenced this issue May 26, 2024
Also clarify the docs that this also checks maps and channels.

Fixes dominikh#1527
arp242 added a commit to arp242/go-tools that referenced this issue May 26, 2024
Also clarify the docs that this also checks maps and channels.

Fixes dominikh#1527
arp242 added a commit to arp242/go-tools that referenced this issue May 26, 2024
Also clarify the docs that this also checks maps and channels.

Fixes dominikh#1527
@arp242
Copy link
Contributor

arp242 commented May 26, 2024

am surprised it doesn’t seem to do the same for maps.

It does, what doesn't work is using a selector like o.m (for maps or slices). FYI.

arp242 added a commit to arp242/go-tools that referenced this issue Jun 1, 2024
Also clarify the docs that this also checks maps and channels.

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

Successfully merging a pull request may close this issue.

3 participants