go version)?$ go version 1.12
yes
go env)?go env Output
$ go env
GOARCH="amd64"
GOBIN=""
GOCACHE="/Users/reilly/Library/Caches/go-build"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="darwin"
GOOS="darwin"
GOPATH="/Users/reilly/league/services:/Users/reilly/go:"
GOPROXY=""
GORACE=""
GOROOT="/usr/local/go"
GOTMPDIR=""
GOTOOLDIR="/usr/local/go/pkg/tool/darwin_amd64"
GCCGO="gccgo"
CC="clang"
CXX="clang++"
CGO_ENABLED="1"
GOMOD=""
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"
GOGCCFLAGS="-fPIC -m64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=/var/folders/gz/4ytqr0r12q1fbx8ct_w3k_880000gn/T/go-build175674008=/tmp/go-build -gno-record-gcc-switches -fno-common"
Ran the nilness analyzer on this (simplified) package:
package foo
import (
"fmt"
)
func Foo() {
var x []int
for _, a := range x {
fmt.Println(a)
}
}
Ideally: a different error about how you're iterating over a nil slice
Less ideally: the same error, but with information telling me where the error is
-: nil dereference in index operation
This kind of error is pretty hard to track down if I'm running the analyzer over a large codebase, because it doesn't say which file or package is failing.
/cc @matloob
This is a major problem that deserves attention. I work for a medium sized tech company looking to adopt golangci-lint and this issue is holding me back.
Change https://golang.org/cl/208599 mentions this issue: go/ssa: add position data in indexed range loops
@vovapi's CL above adds position information to the error message, but I think to improve this further we'd have alter the way go/ssa tracks position information. Something similar was done for staticcheck: https://github.com/dominikh/go-tools/commit/c14c261fd1fd7dec2e23b44bbf8c7b49cbd4e239
Most helpful comment
This is a major problem that deserves attention. I work for a medium sized tech company looking to adopt golangci-lint and this issue is holding me back.