Skip to content

cmd/compile: type inference fails for unused type in generic type alias  #70948

@DmitriyMV

Description

@DmitriyMV

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:

Metadata

Metadata

Assignees

Labels

NeedsInvestigationSomeone must examine and confirm this is a valid issue and not a duplicate of an existing one.TypeInferenceIssue is related to generic type inferencecompiler/runtimeIssues related to the Go compiler and/or runtime.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions