Skip to content

iter: range over seq (variable of type iter.Seq[T]) must have one iteration variable #64645

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

Closed
j178 opened this issue Dec 11, 2023 · 3 comments
Closed
Labels
FrozenDueToAge NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Milestone

Comments

@j178
Copy link
Contributor

j178 commented Dec 11, 2023

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.

@callthingsoff
Copy link
Contributor

I see a TODO here:
https://github.com/golang/go/blob/46ea4ab5cb87e9e5d443029f5f1a4bba012804d3/src/internal/types/testdata/spec/range.go#L29C10-L29C10

	// TODO: Would be nice to 'for range T.M' and 'for range (*T).PM' directly,
	// but there is no gofmt-friendly way to write the error pattern in the right place.

@prattmic prattmic added this to the Go1.23 milestone Dec 11, 2023
@prattmic prattmic added the NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. label Dec 11, 2023
@prattmic
Copy link
Member

cc @rsc

@rsc
Copy link
Contributor

rsc commented Jan 23, 2024

Duplicate of #65236.

@rsc rsc closed this as not planned Won't fix, can't repro, duplicate, stale Jan 23, 2024
@golang golang locked and limited conversation to collaborators Jan 22, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
FrozenDueToAge NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Projects
None yet
Development

No branches or pull requests

5 participants