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

cmd/compile, go/types, types2: unclear error message on initialization loop and invalid parameter type #47059

Open
gazerro opened this issue Jul 5, 2021 · 4 comments
Assignees
Labels
Milestone

Comments

@gazerro
Copy link
Contributor

@gazerro gazerro commented Jul 5, 2021

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

$ go version
go version go1.16.5 darwin/amd64

Does this issue reproduce with the latest release?

Yes

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

go env Output
$ go env
GO111MODULE="on"
GOARCH="amd64"
GOBIN=""
GOCACHE="/Users/marco/Library/Caches/go-build"
GOENV="/Users/marco/Library/Application Support/go/env"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="darwin"
GOINSECURE=""
GOMODCACHE="/Users/marco/go/pkg/mod"
GOOS="darwin"
GOPATH="/Users/marco/go"
GOPROXY="https://proxy.golang.org,direct"
GOROOT="/usr/local/go"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/usr/local/go/pkg/tool/darwin_amd64"
GOVCS=""
GOVERSION="go1.16.5"
GCCGO="gccgo"
AR="ar"
CC="clang"
CXX="clang++"
CGO_ENABLED="1"
GOMOD="/dev/null"
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"
GOGCCFLAGS="-fPIC -arch x86_64 -m64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=/var/folders/z9/xrln_qks56jbzxjbhs04fpm80000gn/T/go-build1476298263=/tmp/go-build -gno-record-gcc-switches -fno-common"

What did you do?

Execute this program

package main

var a = f(5)

func f(a) int { _ = a; return 5 }

func main() {}

https://play.golang.org/p/5H8A96e3nn5

What did you expect to see?

./prog.go:3:5: initialization loop:
	prog.go:3:5: a refers to
	prog.go:5:6: f refers to
	prog.go:3:5: a
./prog.go:5:8: a is not a type

What did you see instead?

./prog.go:3:9: typechecking loop involving f
	prog.go:3:10 f(5)
	prog.go:3:5 a = f(5)
	prog.go:3:5 a
	prog.go:5:7 <func>
	prog.go:5:6 f
	prog.go:5:6 <node DCLFUNC>
./prog.go:5:8: a is not a type

With tip the error is

./test.go:3:9: typechecking loop involving f
	prog.go:3:10 f(5)
	prog.go:3:5 a = f(5)
	prog.go:3:5 a
	prog.go:5:7 <func>
	prog.go:5:6 f
	prog.go:5:6 f
./test.go:5:8: a is not a type
@mknyszek mknyszek added this to the Backlog milestone Jul 7, 2021
@mknyszek
Copy link
Contributor

@mknyszek mknyszek commented Jul 7, 2021

Is this a recent regression or has it been the case for some time now?

@mknyszek
Copy link
Contributor

@mknyszek mknyszek commented Jul 7, 2021

I think CC @griesemer for type/semantic checking error messages?

@gazerro
Copy link
Contributor Author

@gazerro gazerro commented Jul 7, 2021

It is not a recent regression. With Go 1.13 the error is

./prog.go:3:9: typechecking loop involving f
	prog.go:3:10 f(5)
	prog.go:3:5 a = f(5)
	prog.go:o:3:5 a
	prog.go:5:7 <T>
	prog.go:5:6 f
	prog.go:5:6 <node DCLFUNC>
./prog.go:5:8: a is not a type
@griesemer
Copy link
Contributor

@griesemer griesemer commented Jul 7, 2021

Using types2 in the compiler (same for go/types):

$ go tool compile -G=3 x.go
x.go:3:5: invalid recursive type a
	x.go:3:5: a refers to
	x.go:5:6: f refers to
	x.go:3:5: a
x.go:3:5: initialization loop for a
	x.go:3:5: a refers to
	x.go:5:6: f refers to
	x.go:3:5: a

Perhaps slightly better but there should be only one error message.

Thanks for reporting.

Marking for 1.18 in case there's an easy fix, but if not, this is certainly not urgent: we get an error message and we don't crash; also this is a somewhat rare error case.

@griesemer griesemer self-assigned this Jul 7, 2021
@griesemer griesemer removed this from the Backlog milestone Jul 7, 2021
@griesemer griesemer added this to the Go1.18 milestone Jul 7, 2021
@griesemer griesemer changed the title cmd/compile: unclear error message on initialization loop and invalid parameter type cmd/compile, go/types, types2: unclear error message on initialization loop and invalid parameter type Jul 7, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
4 participants