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: generic method appears to use syntax keywords as types #52058

Closed
denis-tingaikin opened this issue Mar 31, 2022 · 1 comment
Closed

Comments

@denis-tingaikin
Copy link

@denis-tingaikin denis-tingaikin commented Mar 31, 2022

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

$ go version
go version go1.18 darwin/arm64

Does this issue reproduce with the latest release?

Yes (1.18)

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

go env Output
$ go env
go env
GO111MODULE="on"
GOARCH="arm64"
GOBIN=""
GOEXE=""
GOEXPERIMENT=""
GOFLAGS=""
GOHOSTARCH="arm64"
GOHOSTOS="darwin"
GOINSECURE=""
GOOS="darwin"
GOPROXY="https://goproxy.io,https://mirrors.aliyun.com/goproxy/"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOVCS=""
GOVERSION="go1.18"
GCCGO="gccgo"
AR="ar"
CC="clang"
CXX="clang++"
CGO_ENABLED="1"
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 -arch arm64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=/var/folders/yv/fd8s2yw54cldnj29jx3qxrh80000gn/T/go-build4280234465=/tmp/go-build -gno-record-gcc-switches -fno-common"

What did you do?

See at https://gotipplay.golang.org/p/Zb7hPmoxFj0 and https://go.dev/play/p/Zb7hPmoxFj0

type AwesomeSlice[T any] []T

// Are you expect this compilable?
func (s AwesomeSlice[nil]) AwesomeMethod1() nil {
	var panic nil
	return panic
}

What did you expect to see?

Compile errors

What did you see instead?

Everything is working

@ianlancetaylor
Copy link
Contributor

@ianlancetaylor ianlancetaylor commented Mar 31, 2022

In Go nil is not a keyword. It is a predeclared identifier (https://go.dev/ref/spec#Predeclared_identifiers). Code is permitted to shadow the predeclared identifiers, and that is what is happening here.

Closing because this is not a bug. In general we suggest asking questions on a forum; see https://go.dev/wiki/Questions. Thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants