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

Cannot pass variadic method expression with variadic of generic type #49516

Closed
kylelemons opened this issue Nov 11, 2021 · 1 comment
Closed
Labels
FrozenDueToAge NeedsFix The path to resolution is known, but the work has not been done. release-blocker
Milestone

Comments

@kylelemons
Copy link
Contributor

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

$ go version
go version devel go1.18-4d0683965b Wed Nov 10 22:16:25 2021 +0000 windows/amd64

Does this issue reproduce with the latest release?

With the latest gotip

What operating system and processor architecture are you using (go env)?

go env Output
$ go env
set GO111MODULE=
set GOARCH=amd64
set GOBIN=
set GOCACHE=C:\Users\kyle\AppData\Local\go-build
set GOENV=C:\Users\kyle\AppData\Roaming\go\env
set GOEXE=.exe
set GOEXPERIMENT=
set GOFLAGS=
set GOHOSTARCH=amd64
set GOHOSTOS=windows
set GOINSECURE=
set GOMODCACHE=C:\Users\kyle\go\pkg\mod
set GONOPROXY=
set GONOSUMDB=
set GOOS=windows
set GOPATH=C:\Users\kyle\go
set GOPRIVATE=
set GOPROXY=https://proxy.golang.org,direct
set GOROOT=C:\Users\kyle\sdk\gotip
set GOSUMDB=sum.golang.org
set GOTMPDIR=
set GOTOOLDIR=C:\Users\kyle\sdk\gotip\pkg\tool\windows_amd64
set GOVCS=
set GOVERSION=devel go1.18-4d0683965b Wed Nov 10 22:16:25 2021 +0000
set GCCGO=gccgo
set GOAMD64=v1
set AR=ar
set CC=gcc
set CXX=g++
set CGO_ENABLED=0
set GOMOD=C:\Users\kyle\dev\generics_exp\go.mod
set GOWORK=
set CGO_CFLAGS=-g -O2
set CGO_CPPFLAGS=
set CGO_CXXFLAGS=-g -O2
set CGO_FFLAGS=-g -O2
set CGO_LDFLAGS=-g -O2
set PKG_CONFIG=pkg-config
set GOGCCFLAGS=-m64 -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=C:\Users\kyle\AppData\Local\Temp\go-build3149543561=/tmp/go-build -gno-record-gcc-switches
GOROOT/bin/go version: go version devel go1.18-4d0683965b Wed Nov 10 22:16:25 2021 +0000 windows/amd64
GOROOT/bin/go tool compile -V: compile version devel go1.18-4d0683965b Wed Nov 10 22:16:25 2021 +0000

What did you do?

This code works, even with generics:

func pushN(push func(*Q[int], int), n int)
package repro

import "testing"

type Q[T any] struct {
	s []T
}

func (q *Q[T]) Push(v T) {
	q.s = append(q.s, v)
}

func pushN(push func(*Q[int], int), n int) {
	var q Q[int]
	for i := 0; i < n; i++ {
		push(&q, i)
	}
}

func TestPushN(t *testing.T) {
	pushN((*Q[int]).Push, 100)
}

However, if I change the Push to be variadic on T:

package repro

import "testing"

type Q[T any] struct {
	s []T
}

func (q *Q[T]) Push(v ...T) {
	q.s = append(q.s, v...)
}

func pushN(push func(*Q[int], ...int), n int) {
	var q Q[int]
	for i := 0; i < n; i++ {
		push(&q, i)
	}
}

func TestPushN(t *testing.T) {
	pushN((*Q[int]).Push, 100)
}

I get

$ gotip test
# generics_exp/dequeue/repro [generics_exp/dequeue/repro.test]
.\repro_test.go:21:17: cannot use a1 (type []int) as type go.shape.int_0 in argument to (*Q[go.shape.int_0]).Push
FAIL    generics_exp/dequeue/repro [build failed]

This works with a non-generic type, of course:

func pushN(push func(*Q, ...int), n int)
package repro

import "testing"

type Q struct {
	s []int
}

func (q *Q) Push(v ...int) {
	q.s = append(q.s, v...)
}

func pushN(push func(*Q, ...int), n int) {
	var q Q
	for i := 0; i < n; i++ {
		push(&q, i)
	}
}

func TestPushN(t *testing.T) {
	pushN((*Q).Push, 100)
}
@cuonglm cuonglm self-assigned this Nov 11, 2021
@cuonglm cuonglm added the NeedsFix The path to resolution is known, but the work has not been done. label Nov 11, 2021
@cuonglm cuonglm added this to the Go1.18 milestone Nov 11, 2021
@gopherbot
Copy link

Change https://golang.org/cl/363314 mentions this issue: cmd/compile: fix missing ddd when building call for function instantiation closure

@rsc rsc unassigned cuonglm Jun 23, 2022
@golang golang locked and limited conversation to collaborators Jun 23, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
FrozenDueToAge NeedsFix The path to resolution is known, but the work has not been done. release-blocker
Projects
None yet
Development

No branches or pull requests

3 participants