go-tools icon indicating copy to clipboard operation
go-tools copied to clipboard

SA5000: sometimes doesn't detect nil maps

Open xy6321 opened this issue 3 years ago • 0 comments

package main

func main() {
	_ = a()
	_ = b()
}

type t struct {
	m map[int64]string
}

func a() (m map[int64]string) {
	m[1] = "string"
	return
}

func b() (m t) {
	m.m[1] = "string"
	return
}

func a() detect nil maps, [{ "resource": "/main.go", "owner": "go-staticcheck", "severity": 4, "message": "assignment to nil map (SA5000)", "source": "go-staticcheck", "startLineNumber": 13, "startColumn": 2, "endLineNumber": 13, "endColumn": 17 }]

but func b() not

go version go version go1.20 linux/amd64

staticcheck -version staticcheck 2023.1 (v0.4.0)

staticcheck -debug.version staticcheck 2023.1 (v0.4.0)

Compiled with Go version: go1.20 Main module: honnef.co/go/[email protected] (sum: h1:lyXVV1c8wUBJRKqI8JgIpT8TW1VDagfYYaxbKa/HoL8=) Dependencies: github.com/BurntSushi/[email protected] (sum: h1:9F2/+DoOYIOksmaJFPw1tGFy1eDnIJXg+UHjuD8lTak=) golang.org/x/exp/[email protected] (sum: h1:Jw5wfR+h9mnIYH+OtGT2im5wV1YGGDora5vTv/aa5bE=) golang.org/x/[email protected] (sum: h1:LapD9S96VoQRhi/GrNTqeBJFrUjs5UHCAtTlgwA5oZA=) golang.org/x/[email protected] (sum: h1:w8ZOecv6NaNa/zC8944JTU3vz4u6Lagfk4RPQxv92NQ=) golang.org/x/[email protected] (sum: h1:9ZNWAi4CYhNv60mXGgAncgq7SGc5qa7C8VZV8Tg7Ggs=)

xy6321 avatar Feb 07 '23 15:02 xy6321