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: type inference fails for unused type in generic type alias #70948

Open
DmitriyMV opened this issue Dec 21, 2024 · 3 comments
Open
Labels
compiler/runtime Issues related to the Go compiler and/or runtime. NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.

Comments

@DmitriyMV
Copy link
Contributor

DmitriyMV commented Dec 21, 2024

Go version

go version devel go1.24-669d87a Thu Dec 19 19:19:59 2024 -0800 darwin/arm64

Output of go env in your module/workspace:

AR='ar'
CC='clang'
CGO_CFLAGS='-O2 -g'
CGO_CPPFLAGS=''
CGO_CXXFLAGS='-O2 -g'
CGO_ENABLED='1'
CGO_FFLAGS='-O2 -g'
CGO_LDFLAGS='-O2 -g'
CXX='clang++'
GCCGO='gccgo'
GO111MODULE=''
GOARCH='arm64'
GOARM64='v8.0'
GOAUTH='netrc'
GOBIN=''
GOCACHE='/Users/dmitry/Library/Caches/go-build'
GODEBUG=''
GOENV='/Users/dmitry/Library/Application Support/go/env'
GOEXE=''
GOEXPERIMENT=''
GOFIPS140='off'
GOFLAGS=''
GOGCCFLAGS='-fPIC -arch arm64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -ffile-prefix-map=/var/folders/59/2slgfdl91td3z8w75b7zh6kw0000gn/T/go-build2195658086=/tmp/go-build -gno-record-gcc-switches -fno-common'
GOHOSTARCH='arm64'
GOHOSTOS='darwin'
GOINSECURE=''
GOMOD='/Users/dmitry/alias_example/go.mod'
GOMODCACHE='/Users/dmitry/go/pkg/mod'
GONOPROXY=''
GONOSUMDB=''
GOOS='darwin'
GOPATH='/Users/dmitry/go'
GOPRIVATE=''
GOPROXY='https://proxy.golang.org,direct'
GOROOT='/Users/dmitry/sdk/gotip'
GOSUMDB='sum.golang.org'
GOTELEMETRY='on'
GOTELEMETRYDIR='/Users/dmitry/Library/Application Support/go/telemetry'
GOTMPDIR=''
GOTOOLCHAIN='local'
GOTOOLDIR='/Users/dmitry/sdk/gotip/pkg/tool/darwin_arm64'
GOVCS=''
GOVERSION='devel go1.24-669d87a Thu Dec 19 19:19:59 2024 -0800'
GOWORK=''
PKG_CONFIG='pkg-config'

What did you do?

$ > cat main.go
package main

type A[V any] = struct{}

func Foo[V any](_ A[V]) {}

func main() {
	Foo(A[int]{})
}

$ > gotip version
go version devel go1.24-669d87a Thu Dec 19 19:19:59 2024 -0800 darwin/arm64

$ > gotip run main.go
# command-line-arguments
./main.go:8:5: in call to Foo, cannot infer V (declared at ./main.go:5:10)

What did you see happen?

Compilation failure.

What did you expect to see?

Successful compilation, even tho type A[V any] = struct{} doesn't make much sense.

Notes:

@seankhliao seankhliao changed the title cmd/go: cannot infer V for generic alias to an empty struct cmd/go: type inference fails for unused type in generic type alias Dec 21, 2024
@dr2chase dr2chase added the NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. label Dec 21, 2024
@dr2chase
Copy link
Contributor

@griesemer @timothy-king

@ianlancetaylor ianlancetaylor changed the title cmd/go: type inference fails for unused type in generic type alias cmd/compile: type inference fails for unused type in generic type alias Dec 21, 2024
@gopherbot gopherbot added the compiler/runtime Issues related to the Go compiler and/or runtime. label Dec 21, 2024
@ianlancetaylor
Copy link
Member

CC @griesemer

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
compiler/runtime Issues related to the Go compiler and/or runtime. 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

5 participants