Skip to content

cmd/compile: Inconsistent type argument inference between generic functions and generic types #78875

Closed as duplicate

Description

@pashaosipyants

Go version

go version go1.26.0 darwin/amd64

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=''
GOAMD64='v1'
GOARCH='amd64'
GOAUTH='netrc'
GOBIN=''
GOCACHE='/Users/pavelosipyants/Library/Caches/go-build'
GOCACHEPROG=''
GODEBUG=''
GOENV='/Users/pavelosipyants/Library/Application Support/go/env'
GOEXE=''
GOEXPERIMENT=''
GOFIPS140='off'
GOFLAGS=''
GOGCCFLAGS='-fPIC -arch x86_64 -m64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -ffile-prefix-map=/var/folders/ys/r_gzqylj4pz_20h8c45t9mx80000gn/T/go-build2592715299=/tmp/go-build -gno-record-gcc-switches -fno-common'
GOHOSTARCH='amd64'
GOHOSTOS='darwin'
GOINSECURE=''
GOMOD='/dev/null'
GOMODCACHE='/Users/pavelosipyants/go/pkg/mod'
GONOPROXY=''
GONOSUMDB=''
GOOS='darwin'
GOPATH='/Users/pavelosipyants/go'
GOPRIVATE=''
GOPROXY='https://proxy.golang.org,direct'
GOROOT='/usr/local/go'
GOSUMDB='sum.golang.org'
GOTELEMETRY='local'
GOTELEMETRYDIR='/Users/pavelosipyants/Library/Application Support/go/telemetry'
GOTMPDIR=''
GOTOOLCHAIN='auto'
GOTOOLDIR='/usr/local/go/pkg/tool/darwin_amd64'
GOVCS=''
GOVERSION='go1.26.0'
GOWORK=''
PKG_CONFIG='pkg-config

What did you do?

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

package main

func f_ok_inference[PT *T, T any]() {}

type t_not_ok_inference[PT *T, T any] struct{}

func main() {
	f_ok_inference[*int]()
	_ = t_not_ok_inference[*int]{}
}

What did you see happen?

Compile failure.

./prog.go:9:6: not enough type arguments for type t_not_ok_inference: have 1, want 2

What did you expect to see?

Compile success.

There appears to be an inconsistency in how type argument inference works for generic functions versus generic types when one type parameter is constrained as a pointer to another.
The compiler allows partial type argument specification with inference for generic functions, but rejects the same pattern for generic types.

Activity

  1. mwriter commented on Apr 20, 2026

    @mwriter

    This is an interesting example of a type inference problem.
    Although we need to look at the docs, and whether there are any restrictions on type inference in interfaces and structures.
    And maybe you'll be interested. Also we collect the problems of type inference here:
    #73527

  2. seankhliao commented on Apr 20, 2026

    @seankhliao
    Member

    see the spec:
    inference is only for functions: https://go.dev/ref/spec#Type_inference

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    compiler/runtimeIssues related to the Go compiler and/or runtime.

    Type

    No type

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions