8000 SA1031: ignore provably empty slices by ibondarenko1 · Pull Request #1856 · dominikh/go-tools · GitHub
[go: up one dir, main page]

Skip to content

SA1031: ignore provably empty slices - #1856

Open
ibondarenko1 wants to merge 1 commit into
dominikh:masterfrom
ibondarenko1:fix/sa1031-empty-slices
Open

ibondarenko1 wants to merge 1 commit into
dominikh:masterfrom
ibondarenko1:fix/sa1031-empty-slices

Conversation

@ibondarenko1
Copy link
Copy Markdown

SA1031 reports overlapping slices for a valid no-op:

b := make([]byte, 2)
base64.StdEncoding.Encode(b[:0], b[:0])

The check identifies the shared backing array and equal start offsets without checking whether either slice has any elements. This change skips the diagnostic when the IR proves a slice is empty. It covers equal bounds, constant zero-length allocation, and full slices of known empty values.

Added four Base64 cases. All four reported unexpected diagnostics on the base revision. With the change, go test ./staticcheck/sa1031 -count=1 and go vet ./staticcheck/sa1031 pass. Existing cases with overlapping non-empty slices still report SA1031.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant

0