Skip to content

cmd/compile: generic code behaves differently from non-generic code #59827

@zigo101

Description

@zigo101

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

$ go version
go version go1.20.3 linux/amd64

Does this issue reproduce with the latest release?

Yes

What did you do?

package main

type I interface {
	M(int)
	P()
}

type V int

func (v V) P()       { println(v) }
func (v *V) M(n int) { *v = V(n) }

type S struct{ *V }

func F[T I](x T) {
	defer x.P()
	x.M(9)
}

func G(x *S) {
	defer x.P()
	x.M(9)
}

func main() {
	{
		var s = S{V: new(V)}
		F(&s) // 9
	}
	{
		var s = S{V: new(V)}
		G(&s) // 0
	}
}

What did you expect to see?

Same behavior.

What did you see instead?

Different behavior.

Metadata

Metadata

Assignees

No one assigned

    Labels

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

    Type

    No type

    Projects

    Status

    Todo

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions