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

simple: S1011 doesn't fire if the for i := range s form is used #881

Closed
ainar-g opened this issue Dec 1, 2020 · 0 comments
Closed

simple: S1011 doesn't fire if the for i := range s form is used #881

ainar-g opened this issue Dec 1, 2020 · 0 comments

Comments

@ainar-g
Copy link
Contributor

ainar-g commented Dec 1, 2020

Synopsis:

package main

import "fmt"

func main() {
	var a = []int{1, 2, 3}
	var b = []int{4, 5, 6}
	var c = []int{7, 8, 9}

	for _, n := range b { /* Line 10. */
		a = append(a, n)
	}

	for i := range c { /* Line 14. */
		n := c[i]
		a = append(a, n)
	}

	fmt.Println(a)
}
$ staticcheck --debug.version
staticcheck (devel, v0.0.1-2020.1.0.20201124073330-56b7c78ddcd8)

Compiled with Go version: go1.15.4
Main module:
	honnef.co/go/tools@v0.0.1-2020.1.0.20201124073330-56b7c78ddcd8 (sum: h1:FkcSm40GciJwcT9dunF0X8Zv336LFcXaHt0k97IBG4Q=)
Dependencies:
	github.com/BurntSushi/toml@v0.3.1 (sum: h1:WXkYYl6Yr3qBf1K79EBnL4mak0OimBfB0XUf9Vl28OQ=)
	golang.org/x/mod@v0.3.0 (sum: h1:RM4zey1++hCTbCVQfnWeKs9/IEsaBLA8vTkd0WVtmH4=)
	golang.org/x/tools@v0.0.0-20201201064407-fd09bd90d85c (sum: h1:D/mVYXCk6gUcyr7WuGlAk/ShHqgARUXc2VQxo27Hmws=)
	golang.org/x/xerrors@v0.0.0-20200804184101-5ec99f83aff1 (sum: h1:go1bK/D/BFZV2I8cIQd1NKEZ+0owSTG1fDTci4IqFcE=)
$ staticcheck --checks=all ./go/tmp/main.go
go/tmp/main.go:10:2: should replace loop with a = append(a, b...) (S1011)

Run 'staticcheck -explain ' or visit https://staticcheck.io/docs/checks for documentation on checks.

Line 14 should be marked as well.

(Found by @EugeneOne1.)

@ainar-g ainar-g added the needs-triage Newly filed issue that needs triage label Dec 1, 2020
@dominikh dominikh added enhancement and removed needs-triage Newly filed issue that needs triage labels Dec 12, 2020
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.

2 participants