Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

generics: incorrect error message with range clause over type sets with multiple underlying types #50738

Closed
perillo opened this issue Jan 21, 2022 · 3 comments

Comments

@perillo
Copy link
Contributor

perillo commented Jan 21, 2022

What version of Go are you using (go version)?

$ go version
go version devel go1.18-59122f85bd Thu Jan 20 16:31:11 2022 +0000 linux/amd64

Does this issue reproduce with the latest release?

What operating system and processor architecture are you using (go env)?

go env Output
$ go env
GO111MODULE="on"
GOARCH="amd64"
GOBIN="/home/manlio/.local/bin"
GOCACHE="/home/manlio/.cache/go-build"
GOENV="/home/manlio/.config/go/env"
GOEXE=""
GOEXPERIMENT=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOINSECURE="*.local"
GOMODCACHE="/home/manlio/.local/lib/go/pkg/mod"
GONOPROXY=""
GONOSUMDB="*.local"
GOOS="linux"
GOPATH="/home/manlio/.local/lib/go:/home/manlio/src/go"
GOPRIVATE=""
GOPROXY="https://proxy.golang.org,direct"
GOROOT="/home/manlio/sdk/gotip"
GOSUMDB="sum.golang.org"
GOTMPDIR="/tmp/gotmp"
GOTOOLDIR="/home/manlio/sdk/gotip/pkg/tool/linux_amd64"
GOVCS=""
GOVERSION="devel go1.18-59122f85bd Thu Jan 20 16:31:11 2022 +0000"
GCCGO="gccgo"
GOAMD64="v1"
AR="ar"
CC="gcc"
CXX="g++"
CGO_ENABLED="1"
GOMOD="/home/manlio/src/go/src/test.localhost/type-params/proposal/go.mod"
GOWORK=""
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 -fmessage-length=0 -fdebug-prefix-map=/tmp/gotmp/go-build3690629167=/tmp/go-build -gno-record-gcc-switches"
GOROOT/bin/go version: go version devel go1.18-59122f85bd Thu Jan 20 16:31:11 2022 +0000 linux/amd64
GOROOT/bin/go tool compile -V: compile version devel go1.18-59122f85bd Thu Jan 20 16:31:11 2022 +0000
uname -sr: Linux 5.15.13-arch1-1
/usr/lib/libc.so.6: GNU C Library (GNU libc) release release version 2.33.
gdb --version: GNU gdb (GDB) 11.1

What did you do?

https://gotipplay.golang.org/p/muzbkNYCk31

What did you expect to see?

An error message reporting that range over a type with an union constraint with multiple elements is not allowed.

What did you see instead?

./prog.go:15:20: cannot range over it (variable of type S constrained by Iterable[E]) (S has no structural type)

P.S.:
The concept of multiple underlying types used in some CL is not defined in the Type Parameter Proposal and in The Go Programming Language Specification.

Thanks.

@ianlancetaylor
Copy link
Member

Thanks. The spec has not yet been updated. The error message is correct for what we expect to implement in 1.18. Closing because there is nothing to change here.

@perillo
Copy link
Contributor Author

perillo commented Jan 21, 2022

Isn't the message S has no structural type incorrect?

This example: https://gotipplay.golang.org/p/dS-BdrZyZ8z
reports the same error:

prog.go:6:20: cannot range over it (variable of type S constrained by any) (S has no structural type)

with the difference that in this case S really has no structural type (assuming that I'm interpreting the term structural type correctly).

Thanks.

@ianlancetaylor
Copy link
Member

In the original example the type of S is either []T or []int. That means that it doesn't have a structural type. A structural type is a single type, but here there are two. It's true that they are both slices, but they are slices of different element types.

@golang golang locked and limited conversation to collaborators Jan 21, 2023
# for free to subscribe to this conversation on GitHub. Already have an account? #.
Projects
None yet
Development

No branches or pull requests

3 participants