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: can't assign pointer from generic type to generic interface satisfied by pointer receiver #47747

Closed
4ad opened this issue Aug 17, 2021 · 6 comments
Labels
FrozenDueToAge NeedsFix The path to resolution is known, but the work has not been done.
Milestone

Comments

@4ad
Copy link
Member

4ad commented Aug 17, 2021

On tip (a304273) with -gcflags -G=3.

Repro:

package p

type Fooer[t any] interface {
	Foo(Barer[t])
}
type Barer[t any] interface {
	Bar(t)
}

type Foo[t any] t
type Bar[t any] t

func (l Foo[t]) Foo(v Barer[t]) { v.Bar(t(l)) }
func (b *Bar[t]) Bar(l t)       { *b = Bar[t](l) }

func f[t any](f Fooer[t]) t {
	var b Bar[t]
	f.Foo(&b)
	return t(b)
}

Compiler aborts with:

go build -gcflags -G=3 g.go
# command-line-arguments
./g.go:18:8: incompatible type: cannot use &b (value of type *Bar[t]) as Barer[t] value

Works with go2go: https://go2goplay.golang.org/p/HKqbj1Y6Ahh

@4ad 4ad added this to the Go1.18 milestone Aug 17, 2021
@4ad
Copy link
Member Author

4ad commented Aug 17, 2021

Simpler repro:

package p

type Fooer[t any] interface {
	Foo()
}

type Foo[t any] t

func (f *Foo[t]) Foo() {}

func f[t any](v t) {
	var f = Foo[t](v)
	_ = Fooer[t](&f)
}

go build -gcflags -G=3 g.go
# command-line-arguments
./g.go:13:15: cannot convert &f (value of type *Foo[t]) to Fooer[t]

Works with go2go: https://go2goplay.golang.org/p/TSQHwwv_p3o

@4ad 4ad changed the title cmd/compile: compiler rejects assignment of value of generic type to satisfied interface cmd/compile: can't assign pointer from generic type to generic interface satisfied by pointer receiver Aug 17, 2021
@mknyszek
Copy link
Contributor

CC @ianlancetaylor @griesemer because I'm not actually sure what the rules are around this case.

@mknyszek mknyszek added the NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. label Aug 17, 2021
@griesemer
Copy link
Contributor

Simpler reproducer: https://go2goplay.golang.org/p/NLPVJOJuWIY (works with go2go but not with current compiler).

@griesemer griesemer self-assigned this Aug 17, 2021
@griesemer
Copy link
Contributor

Direct reproducer:

package p

type T[P any] P

func (T[_]) m() {}

func _[P any](x *T[P]) {
        x.m()
}

@griesemer griesemer added NeedsFix The path to resolution is known, but the work has not been done. and removed NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. labels Aug 17, 2021
@gopherbot
Copy link

Change https://golang.org/cl/342990 mentions this issue: cmd/compile/internal/types2: fix lookup for type-parameter based type

@gopherbot
Copy link

Change https://golang.org/cl/342991 mentions this issue: go/types: fix method lookup for type-parameter based types

gopherbot pushed a commit that referenced this issue Aug 17, 2021
…ed types

Pointers to type parameters don't have methods, but pointers to
defined types whose underlying types are type parameters may have
methods. Fix the respective test.

For #47747.

Change-Id: I1de47be094ed9297f0e7782538011657c37c5adc
Reviewed-on: https://go-review.googlesource.com/c/go/+/342990
Trust: Robert Griesemer <gri@golang.org>
Run-TryBot: Robert Griesemer <gri@golang.org>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Robert Findley <rfindley@google.com>
@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.
Projects
None yet
Development

No branches or pull requests

4 participants