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

go/types, types2: stack overflow results after naming type parameter after interface name. #50517

Closed
bmizerany opened this issue Jan 9, 2022 · 2 comments
Labels
FrozenDueToAge NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Milestone

Comments

@bmizerany
Copy link
Contributor

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

$ go version
go version go1.18beta1 darwin/arm64

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=""
GOARCH="arm64"
GOBIN=""
GOCACHE="/Users/bmizerany/Library/Caches/go-build"
GOENV="/Users/bmizerany/Library/Application Support/go/env"
GOEXE=""
GOEXPERIMENT=""
GOFLAGS=""
GOHOSTARCH="arm64"
GOHOSTOS="darwin"
GOINSECURE=""
GOMODCACHE="/Users/bmizerany/go/pkg/mod"
GONOPROXY="tier.run"
GONOSUMDB="tier.run"
GOOS="darwin"
GOPATH="/Users/bmizerany/go"
GOPRIVATE=""
GOPROXY="https://proxy.golang.org,direct"
GOROOT="/usr/local/go"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/usr/local/go/pkg/tool/darwin_arm64"
GOVCS=""
GOVERSION="go1.18beta1"
GCCGO="gccgo"
AR="ar"
CC="clang"
CXX="clang++"
CGO_ENABLED="1"
GOMOD="/Users/bmizerany/go/src/exhausted/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 -arch arm64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=/var/folders/rf/6fdgwbmj2rxf1jw13q4fv7h80000gn/T/go-build4012310581=/tmp/go-build -gno-record-gcc-switches -fno-common"
GOROOT/bin/go version: go version go1.18beta1 darwin/arm64
GOROOT/bin/go tool compile -V: compile version go1.18beta1
uname -v: Darwin Kernel Version 21.1.0: Wed Oct 13 17:33:24 PDT 2021; root:xnu-8019.41.5~1/RELEASE_ARM64_T8101
ProductName:	macOS
ProductVersion:	12.0.1
BuildVersion:	21A559
lldb --version: lldb-1300.0.32.4
Swift version 5.5.1-dev

What did you do?

I wrote this package that names a type parameter the same as its interface and ran `go build .'

exhausted % /bin/cat exhausted.go 
package issue

type I interface {
	int | string
}

func foo[I I](v Thing) {}

What did you expect to see?

It build or provide a helpful error about what I did wrong, especially something around Thing because it is undefined, but it seems Go flipped a switch before it noticed.

What did you see instead?

# blake.io/exausted/cmd/exhausted
runtime: goroutine stack exceeds 1000000000-byte limit
runtime: sp=0x14020460390 stack=[0x14020460000, 0x14040460000]
fatal error: stack overflow

runtime stack:
runtime.throw({0x100dcd86d?, 0x10145a500?})
	/usr/local/go/src/runtime/panic.go:992 +0x50
runtime.newstack()
	/usr/local/go/src/runtime/stack.go:1101 +0x46c
runtime.morestack()
	/usr/local/go/src/runtime/asm_arm64.s:310 +0x70

goroutine 1 [running]:
cmd/compile/internal/types2.(*TypeParam).iface(0x140003d7350)
	/usr/local/go/src/cmd/compile/internal/types2/typeparam.go:99 +0x23c fp=0x14020460390 sp=0x14020460390 pc=0x100d0977c
cmd/compile/internal/types2.(*TypeParam).Underlying(0x0?)
	/usr/local/go/src/cmd/compile/internal/types2/typeparam.go:88 +0x20 fp=0x140204603b0 sp=0x14020460390 pc=0x100d094b0
cmd/compile/internal/types2.under({0x101006548?, 0x140003d7350?})
	/usr/local/go/src/cmd/compile/internal/types2/type.go:27 +0x68 fp=0x140204603d0 sp=0x140204603b0 pc=0x100d088c8
cmd/compile/internal/types2.(*TypeParam).iface(0x140003d7350)
	/usr/local/go/src/cmd/compile/internal/types2/typeparam.go:104 +0x38 fp=0x14020460430 sp=0x140204603d0 pc=0x100d09578
cmd/compile/internal/types2.(*TypeParam).Underlying(0x0?)
	/usr/local/go/src/cmd/compile/internal/types2/typeparam.go:88 +0x20 fp=0x14020460450 sp=0x14020460430 pc=0x100d094b0
cmd/compile/internal/types2.under({0x101006548?, 0x140003d7350?})
	/usr/local/go/src/cmd/compile/internal/types2/type.go:27 +0x68 fp=0x14020460470 sp=0x14020460450 pc=0x100d088c8
cmd/compile/internal/types2.(*TypeParam).iface(0x140003d7350)
	/usr/local/go/src/cmd/compile/internal/types2/typeparam.go:104 +0x38 fp=0x140204604d0 sp=0x14020460470 pc=0x100d09578
cmd/compile/internal/types2.(*TypeParam).Underlying(0x0?)
	/usr/local/go/src/cmd/compile/internal/types2/typeparam.go:88 +0x20 fp=0x140204604f0 sp=0x140204604d0 pc=0x100d094b0
cmd/compile/internal/types2.under({0x101006548?, 0x140003d7350?})
	/usr/local/go/src/cmd/compile/internal/types2/type.go:27 +0x68 fp=0x14020460510 sp=0x140204604f0 pc=0x100d088c8
cmd/compile/internal/types2.(*TypeParam).iface(0x140003d7350)
	/usr/local/go/src/cmd/compile/internal/types2/typeparam.go:104 +0x38 fp=0x14020460570 sp=0x14020460510 pc=0x100d09578
cmd/compile/internal/types2.(*TypeParam).Underlying(0x0?)
	/usr/local/go/src/cmd/compile/internal/types2/typeparam.go:88 +0x20 fp=0x14020460590 sp=0x14020460570 pc=0x100d094b0
cmd/compile/internal/types2.under({0x101006548?, 0x140003d7350?})
	/usr/local/go/src/cmd/compile/internal/types2/type.go:27 +0x68 fp=0x140204605b0 sp=0x14020460590 pc=0x100d088c8
cmd/compile/internal/types2.(*TypeParam).iface(0x140003d7350)
	/usr/local/go/src/cmd/compile/internal/types2/typeparam.go:104 +0x38 fp=0x14020460610 sp=0x140204605b0 pc=0x100d09578
cmd/compile/internal/types2.(*TypeParam).Underlying(0x0?)
	/usr/local/go/src/cmd/compile/internal/types2/typeparam.go:88 +0x20 fp=0x14020460630 sp=0x14020460610 pc=0x100d094b0
cmd/compile/internal/types2.under({0x101006548?, 0x140003d7350?})
	/usr/local/go/src/cmd/compile/internal/types2/type.go:27 +0x68 fp=0x14020460650 sp=0x14020460630 pc=0x100d088c8
cmd/compile/internal/types2.(*TypeParam).iface(0x140003d7350)
	/usr/local/go/src/cmd/compile/internal/types2/typeparam.go:104 +0x38 fp=0x140204606b0 sp=0x14020460650 pc=0x100d09578
cmd/compile/internal/types2.(*TypeParam).Underlying(0x0?)
	/usr/local/go/src/cmd/compile/internal/types2/typeparam.go:88 +0x20 fp=0x140204606d0 sp=0x140204606b0 pc=0x100d094b0
cmd/compile/internal/types2.under({0x101006548?, 0x140003d7350?})
	/usr/local/go/src/cmd/compile/internal/types2/type.go:27 +0x68 fp=0x140204606f0 sp=0x140204606d0 pc=0x100d088c8

...additional frames elided...

This may possibly be related to or a duplicate of: #48619.

@ianlancetaylor
Copy link
Contributor

CC @griesemer @findleyr

@ianlancetaylor ianlancetaylor added the NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. label Jan 10, 2022
@ianlancetaylor ianlancetaylor added this to the Go1.18 milestone Jan 10, 2022
@griesemer
Copy link
Contributor

griesemer commented Jan 10, 2022

This is fixed at tip. For

package issue

type I interface {
	int | string
}

func foo[I I](v I) {}

the compiler correctly reports:

cannot use a type parameter as constraint

Closing.

@golang golang locked and limited conversation to collaborators Jan 10, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
FrozenDueToAge NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Projects
None yet
Development

No branches or pull requests

4 participants