Go version
go version go1.23.0 linux/amd64
Output of go env
in your module/workspace:
GO111MODULE=''
GOARCH='amd64'
GOBIN=''
GOCACHE='/home/dungdm93/.cache/go-build'
GOENV='/home/dungdm93/.config/go/env'
GOEXE=''
GOEXPERIMENT=''
GOFLAGS=''
GOHOSTARCH='amd64'
GOHOSTOS='linux'
GOINSECURE=''
GOMODCACHE='/home/dungdm93/go/pkg/mod'
GONOPROXY='example.com/example/*'
GONOSUMDB='example.com/example/*'
GOOS='linux'
GOPATH='/home/dungdm93/go'
GOPRIVATE='example.com/example/*'
GOPROXY='https://proxy.golang.org,direct'
GOROOT='/usr/local/go'
GOSUMDB='sum.golang.org'
GOTMPDIR=''
GOTOOLCHAIN='auto'
GOTOOLDIR='/usr/local/go/pkg/tool/linux_amd64'
GOVCS=''
GOVERSION='go1.23.0'
GODEBUG=''
GOTELEMETRY='local'
GOTELEMETRYDIR='/home/dungdm93/.config/go/telemetry'
GCCGO='gccgo'
GOAMD64='v1'
AR='ar'
CC='gcc'
CXX='g++'
CGO_ENABLED='1'
GOMOD='/dev/null'
GOWORK=''
CGO_CFLAGS='-O2 -g'
CGO_CPPFLAGS=''
CGO_CXXFLAGS='-O2 -g'
CGO_FFLAGS='-O2 -g'
CGO_LDFLAGS='-O2 -g'
PKG_CONFIG='pkg-config'
GOGCCFLAGS='-fPIC -m64 -pthread -Wl,--no-gc-sections -fmessage-length=0 -ffile-prefix-map=/tmp/go-build883436730=/tmp/go-build -gno-record-gcc-switches'
What did you do?
package main
import "iter"
func Seq() iter.Seq[string] {
return nil
}
func main() {
var l []any = nil
for _, v := range l { // run normally
println(v)
}
var m map[string]any = nil
for k, v := range m { // run normally
println(k, v)
}
for e := range Seq() { // panic: runtime error: nil pointer dereference
println(e)
}
}
What did you see happen?
panic: runtime error: nil pointer dereference
when iter.Seq
is nil
What did you expect to see?
Run successfully, as the same way as range over nil map and list
Comment From: gabyhelp
Related Issues and Documentation
- proposal: spec: range over nil function values should not panic #65629 (closed)
- iter: `iter.Seq` returns incorrect values for subsequent next calls #64646 (closed)
- Len(slice) returns a non-zero positive number, but accessing first element results in panic #42037 (closed)
- cmd/compile: ICE compiling rangefunc for \< 1.23 in combination with Cgo #67497 (closed)
- General function call #50712 (closed)
- runtime: panic in mapaccess2_faststr (suspected data race) #65115 (closed)
- cmd/compile: internal compiler error: panic: runtime error: index out of range [0] with length 0 #51765 (closed)
- net: mapErr causes panic #60029 (closed)
- runtime: endless traceback when panic in generics funtion #58513 (closed)
- proposal: iter: Allow nil iterators #68931 (closed)
(Emoji vote if this was helpful or unhelpful; more detailed feedback welcome in this discussion.)
Comment From: cuonglm
Duplicated of https://github.com/golang/go/issues/65629