Closed as not planned
Closed as not planned
Description
Go version
go version devel go1.22-46ea4ab Sat Dec 9 21:48:06 2023 +0000 darwin/amd64
What operating system and processor architecture are you using (go env
)?
GO111MODULE=''
GOARCH='amd64'
GOBIN=''
GOCACHE='/Users/jo/Library/Caches/go-build'
GOENV='/Users/jo/Library/Application Support/go/env'
GOEXE=''
GOEXPERIMENT='rangefunc'
GOFLAGS=''
GOHOSTARCH='amd64'
GOHOSTOS='darwin'
GOINSECURE=''
GOMODCACHE='/Users/jo/go/pkg/mod'
GONOPROXY=''
GOOS='darwin'
GOPATH='/Users/jo/go'
GOPRIVATE=''
GOROOT='/Users/jo/sdk/gotip'
GOSUMDB='sum.golang.org'
GOTMPDIR=''
GOTOOLCHAIN='auto'
GOTOOLDIR='/Users/jo/sdk/gotip/pkg/tool/darwin_amd64'
GOVCS=''
GOVERSION='devel go1.22-46ea4ab Sat Dec 9 21:48:06 2023 +0000'
GCCGO='gccgo'
GOAMD64='v1'
AR='ar'
CC='clang'
CXX='clang++'
CGO_ENABLED='0'
GOMOD='/Users/jo/code/it/go.mod'
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 -arch x86_64 -m64 -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -ffile-prefix-map=/var/folders/sw/0cn9x8611_xdn6c20pxd96m40000ks/T/go-build14739506649094477967=/tmp/go-build -gno-record-gcc-switches -fno-common'
What did you do?
package it
import "iter"
func Count[T any](seq iter.Seq[T]) (cnt int) {
for range seq { // does not compile
cnt++
}
return
}
func Count2[T any](seq iter.Seq[T]) (cnt int) {
for _ = range seq { // compiles ok
cnt++
}
return
}
What did you expect to see?
This program compiles ok.
What did you see instead?
# command-line-arguments
./f.go:6:12: range over seq (variable of type iter.Seq[T]) must have one iteration variable
Since Count
does care about the value, from previous experience of for-range
, we tend to omit the blank identifier, but that is a compile error.