Skip to content

cmd/compile: wrappers for methods incorrectly shared #81286

Description

@randall77

It looks like we're sometimes oversharing wrappers for methods, when the methods have the same name but different argument signatures. This is almost certainly a bug in CL 790740.

Reproducer:
go.mod:

module foo.bar

go 1.26.5

a/a.go:

package a

type W struct {
}

func (t W) M(x int) {
	println("a.W", x)
}

b/b.go:

package b

type W struct {
}

func (t W) M() {
	println("b.W")
}

main.go

package main

import (
	"foo.bar/a"
	"foo.bar/b"
)

type I interface {
	M(int)
}

type J interface {
	M()
}

var i I
var j J

type A struct {
	a.W
}
type B struct {
	b.W
}

func init() {
	i = A{}
	j = B{}
}

func main() {
	i.M(9)
	j.M()
}

In 1.27, it prints

$ go run .
a.W 9
b.W

At tip, it prints

a.W 9
a.W 0

Discovered in Google's internal test suite.

It looks like we're somehow conflating the wrappers for the two different types. I'm not sure exactly how yet.

@jakebailey

Activity

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

    Type

    No type

    Projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions