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: peculiar error message caused by two type parameters with the same name #51177

Closed
KZiemian opened this issue Feb 13, 2022 · 5 comments
Closed
Labels
NeedsFix
Milestone

Comments

@KZiemian
Copy link

@KZiemian KZiemian commented Feb 13, 2022

$ go version
go version go1.18beta2 linux/amd64
go env Output
$ go env
GO111MODULE=""
GOARCH="amd64"
GOBIN=""
GOCACHE="/home/kamil/.cache/go-build"
GOENV="/home/kamil/.config/go/env"
GOEXE=""
GOEXPERIMENT=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOINSECURE=""
GOMODCACHE="/home/kamil/go/pkg/mod"
GONOPROXY=""
GONOSUMDB=""
GOOS="linux"
GOPATH="/home/kamil/go"
GOPRIVATE=""
GOPROXY="https://proxy.golang.org,direct"
GOROOT="/home/kamil/sdk/go1.18beta2"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/home/kamil/sdk/go1.18beta2/pkg/tool/linux_amd64"
GOVCS=""
GOVERSION="go1.18beta2"
GCCGO="gccgo"
GOAMD64="v1"
AR="ar"
CC="gcc"
CXX="g++"
CGO_ENABLED="1"
GOMOD="/home/kamil/go/src/github.com/KZiemian/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/go-build1092432607=/tmp/go-build -gno-record-gcc-switches"

I try to test Go type parameters in all ways that I can, so I checked what defining two type parameters with the same name do. Compiling this code give on my computer error message

# command-line-arguments
./Go-s11-26.go:13:33: T redeclared in this block
            /home/kamil/go/src/github.com/KZiemian/Go-s11-26.go:13:19: other declaration of T
./Go-s11-26.go:30:46: cannot infer T (/home/kamil/go/src/github.com/KZiemian/Go-s11-26.go:13:33)

Maybe it is as it should be, but it looks somewhat wrong to me. Someone with bigger expedience should judge it.

Slightly different version of code, also give similar error message.

@randall77
Copy link
Contributor

@randall77 randall77 commented Feb 14, 2022

The first error looks exactly right. It's saying you declared T twice, at line 13 (19 and 33 are the column numbers).
The second error is kind of spurious, resulting from the fact that the thing you're calling didn't typecheck correctly. That error should probably be suppressed.

@hopehook
Copy link
Contributor

@hopehook hopehook commented Feb 14, 2022

Perhaps correct code is like this: https://go.dev/play/p/sd9bia4ybSv?v=gotip

@KZiemian
Copy link
Author

@KZiemian KZiemian commented Feb 14, 2022

@randall77 Does showing full path in "/home/kamil/go/src/github.com/KZiemian/Go-s11-26.go:13:19: other declaration of T" is correct? It feels wrong to me, but this may be just my.

@hopehook I didn't think how correct code would look like. I just tried to test Go1.18beta in every way that I can imagine, even the silly one, and look if something crash/give weird result. I now working through Type Parameters Proposal to find answers to few true problems that I have. This is just byproduct of it.

@randall77
Copy link
Contributor

@randall77 randall77 commented Feb 14, 2022

I see, that sometimes-relative-sometimes-absolute thing is weird.

I can't reproduce by invoking the compiler directly, but I can using go build. It happens with other errors like this also.

package main

func f(x int, x int) {
}
% ~/go1.18beta2/bin/go tool compile tmp1.go
tmp1.go:3:15: x redeclared in this block
	tmp1.go:3:8: other declaration of x
% ~/go1.18beta2/bin/go build tmp1.go       
# command-line-arguments
./tmp1.go:3:15: x redeclared in this block
	/Users/khr/gowork/tmp1.go:3:8: other declaration of x

@gopherbot
Copy link

@gopherbot gopherbot commented Feb 14, 2022

Change https://go.dev/cl/385755 mentions this issue: cmd/go: enable file shortening for lines starting with \t

@dmitshur dmitshur added this to the Go1.18 milestone Feb 14, 2022
@dmitshur dmitshur added the NeedsFix label Feb 14, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
NeedsFix
Projects
None yet
Development

No branches or pull requests

5 participants