Skip to content
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

generics: a type declarations inside generic functions in some cases is not reported in the error report #50726

Closed
perillo opened this issue Jan 20, 2022 · 2 comments

Comments

@perillo
Copy link
Contributor

perillo commented Jan 20, 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-build1471284302=/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?

I have a source file with code that should compile according to the Type Parameter Proposal but is invalid in go1.18:
https://gotipplay.golang.org/p/A4_vnuyiy_H

It contains several errors.

What did you expect to see?

The compiler to report the error
type declarations inside generic functions are not currently supported.

What did you see instead?

./prog.go:23:9: p.x undefined (type T has no field or method x)
./prog.go:25:4: p.x undefined (type T has no field or method x)
./prog.go:36:23: cannot use generic type Iterable[T any] without instantiation
./prog.go:74:35: cannot use a type parameter as RHS in type declaration

The compiler reports the error in the S.Build() method only when removing all the unrelated invalid code.

@randall77
Copy link
Contributor

The error "type declarations inside generic functions are not currently supported" is produced at a later phase in the compiler than those other errors. The compiler exits before that later phase when those other errors happen.

It would be nice to produce them all at one go, but I don't think it is necessary. Lots of non-generic errors have that property currently. For instance, this program:

package main

func f() {
	var x int
}

produces a declared but not used error. The following program also has that error, but the compiler exits much earlier and never gets to the phase that produces it.

package main

zzz

func f() {
	var x int
}

@ianlancetaylor
Copy link
Member

Closing because the current behavior is OK and there is a lot of other stuff to do first. We can take this up again at some later date if it really seems worthwhile.

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

No branches or pull requests

4 participants