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: No error when using interface with typeset with variable #52139

Closed
icholy opened this issue Apr 4, 2022 · 4 comments
Closed

cmd/compile: No error when using interface with typeset with variable #52139

icholy opened this issue Apr 4, 2022 · 4 comments

Comments

@icholy
Copy link

icholy commented Apr 4, 2022

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

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

What did you do?

package main

func main() {
	var _ interface{ string | any } = "test"
}

https://go.dev/play/p/L9p1kcNJs9O

What did you expect to see?

./prog.go:4:8: interface contains type constraints

Go build failed.

What did you see instead?

Compiled successfully.

@icholy icholy changed the title cmd/compile: No error when using interface with typeset in value context cmd/compile: No error when using interface with typeset with variable Apr 4, 2022
@mdempsky
Copy link
Member

mdempsky commented Apr 4, 2022

What's the expected behavior here? I didn't think interface{ string | any } was valid as a normal variable type, but semantically I guess it denotes the same interface as interface{}?

/cc @griesemer @ianlancetaylor @findleyr

@mdempsky
Copy link
Member

mdempsky commented Apr 4, 2022

Spec says "Interfaces whose type sets can be defined entirely by a list of methods are called basic interfaces."

So that suggests to me that it's intended that interface{ string | any } is a basic interface type, and thus should be valid as a variable type. And the compiler is correct to accept it (i.e., this issue can be closed without further action).

Related #52124.

@griesemer
Copy link
Contributor

@mdempsky Correct. This interface is the same as interface{} and thus permitted in this context.

@gopherbot
Copy link

Change https://go.dev/cl/398094 mentions this issue: test: extend issue52124.go to also test #52139

gopherbot pushed a commit that referenced this issue Apr 7, 2022
Change-Id: I7da79d52d50d96536a8175ba08e9da551d07fadd
Reviewed-on: https://go-review.googlesource.com/c/go/+/398094
Trust: Matthew Dempsky <mdempsky@google.com>
Run-TryBot: Matthew Dempsky <mdempsky@google.com>
Reviewed-by: Robert Griesemer <gri@golang.org>
Reviewed-by: Cuong Manh Le <cuong.manhle.vn@gmail.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
@golang golang locked and limited conversation to collaborators Apr 4, 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