Skip to content

reflect: Type.CanSeq[2]: false positive for Seq-like function types with named bool type #77542

Description

@rothelius

Go version

go version go1.26.0 darwin/arm64

Output of go env in your module/workspace:

AR='ar'
CC='clang'
CGO_CFLAGS='-O2 -g'
CGO_CPPFLAGS=''
CGO_CXXFLAGS='-O2 -g'
CGO_ENABLED='1'
CGO_FFLAGS='-O2 -g'
CGO_LDFLAGS='-O2 -g'
CXX='clang++'
GCCGO='gccgo'
GO111MODULE='on'
GOARCH='arm64'
GOARM64='v8.0'
GOAUTH='netrc'
GOBIN='/Users/fabianr/go/bin'
GOCACHE='/Users/fabianr/Library/Caches/go-build'
GOCACHEPROG=''
GODEBUG=''
GOENV='/Users/fabianr/Library/Application Support/go/env'
GOEXE=''
GOEXPERIMENT=''
GOFIPS140='off'
GOFLAGS=''
GOGCCFLAGS='-fPIC -arch arm64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -ffile-prefix-map=/var/folders/81/cvjd0t010fgbf1nc2p9xcq4w0000gn/T/go-build2924183767=/tmp/go-build -gno-record-gcc-switches -fno-common'
GOHOSTARCH='arm64'
GOHOSTOS='darwin'
GOINSECURE=''
GOMOD='/Users/fabianr/svn/be/trunk/gamelogic/gohome/src/elk/go.mod'
GOMODCACHE='/Users/fabianr/svn/be/trunk/gamelogic/gohome/pkg/mod'
GONOPROXY=''
GONOSUMDB=''
GOOS='darwin'
GOPATH='/Users/fabianr/svn/be/trunk/gamelogic/gohome'
GOPRIVATE=''
GOPROXY='https://proxy.golang.org,direct'
GOROOT='/usr/local/go'
GOSUMDB='sum.golang.org'
GOTELEMETRY='local'
GOTELEMETRYDIR='/Users/fabianr/Library/Application Support/go/telemetry'
GOTMPDIR=''
GOTOOLCHAIN='auto'
GOTOOLDIR='/usr/local/go/pkg/tool/darwin_arm64'
GOVCS=''
GOVERSION='go1.26.0'
GOWORK=''
PKG_CONFIG='pkg-config'

What did you do?

Ran the following:

type Bool bool

fn := func(func(int, int) Bool) {}

fmt.Println(reflect.TypeOf(fn).CanSeq2()) // true

What did you see happen?

CanSeq and CanSeq2 both return true.

What did you expect to see?

Trying to range over fn currently won't compile, so I would expect CanSeq and CanSeq2 to reflect this and return false.

See issue #71164.

Activity

  1. added
    BugReportIssues describing a possible bug in the Go implementation.
    on Feb 11, 2026
  2. adonovan commented on Feb 11, 2026

    @adonovan
    Member

    I agree this is a bug; range-over-func allows the func type to be named (e.g. iter.Seq) or unnamed, but the result of the yield function must be exactly the built-in bool type and not a named boolean type.

  3. JunyangShao commented on Feb 11, 2026

    @JunyangShao
    Contributor

    @golang/runtime

  4. added
    NeedsInvestigationSomeone must examine and confirm this is a valid issue and not a duplicate of an existing one.
    on Feb 11, 2026
  5. rothelius commented on Feb 12, 2026

    @rothelius
    Author

    I agree this is a bug; range-over-func allows the func type to be named (e.g. iter.Seq) or unnamed, but the result of the yield function must be exactly the built-in bool type and not a named boolean type.

    For range-over-func even the yield function type can be named! It's only the boolean return type of the yield function that has to be precisely bool.

    As it stands, you might argue that Type.CanSeq[2] behaves correctly, because Value.Seq[2] succeeds when Type.CanSeq[2] returns true, even if the corresponding for ... range loop fails to compile.

    Then again, perhaps this is in order, seeing as #71913 was closed (signifying it's not a bug that you can't use Value.Seq on a Value containing an iter.Seq2, even though the language itself allows for foo := range seq2).

  6. qiulaidongfeng commented on Feb 13, 2026

    @qiulaidongfeng
    Member

    for reference

    that Type.CanSeq[2] behaves correctly, because Value.Seq[2] succeeds when Type.CanSeq[2] returns true

    That's what I thought when I sent CL 578815.

    If is a bug,If modifications are needed, the relevant code can be found in
    https://github.com/golang/go/blob/master/src/reflect/type.go#L944C1-L958C2
    `

  7. gopherbot commented on Feb 14, 2026

    @gopherbot
    Contributor

    Change https://go.dev/cl/745580 mentions this issue: reflect: fix support for iter with named boolean in Seq/Seq2

  8. added
    FixPendingIssues that have a fix which has not yet been reviewed or submitted.
    on Feb 18, 2026
  9. added this to the Backlog milestone on Feb 18, 2026
  10. griesemer commented on Feb 19, 2026

    @griesemer
    Contributor

    I agree that this is a bug as long as #71164 is not accepted.

  11. added a commit that references this issue on Feb 25, 2026
    0ac9d84
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    BugReportIssues describing a possible bug in the Go implementation.FixPendingIssues that have a fix which has not yet been reviewed or submitted.NeedsInvestigationSomeone must examine and confirm this is a valid issue and not a duplicate of an existing one.compiler/runtimeIssues related to the Go compiler and/or runtime.

    Type

    No type

    Projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions