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: identical generic types compare unequal #49245

rogpeppe opened this issue Oct 31, 2021 · 3 comments

cmd/compile: identical generic types compare unequal #49245

rogpeppe opened this issue Oct 31, 2021 · 3 comments


Copy link

@rogpeppe rogpeppe commented Oct 31, 2021

commit 8e3d5f0

This bug was found by @FiloSottile in

Here's a smaller testscript reproducer:

go run ./pkg1

-- go.mod --
module m

go 1.18
-- pkg1/main.go --
package main

import (


func main() {
	i1 := pkg3.GetI()
	i2 := pkg2.Inst
	instEqual := i1 == i2
	if !instEqual {
		v1, v2 := reflect.ValueOf(i1), reflect.ValueOf(i2)
		ptrEqual := v1.Pointer() == v2.Pointer()
		typeEqual := v1.Type() == v2.Type()
		if !ptrEqual {
			fmt.Printf("pointer values are unequal\n")
		if !typeEqual {
			fmt.Printf("types are not equal\n\t%v\n\t%v\n", v1.Type(), v2.Type())

-- pkg2/x.go --
package pkg2

import "m/pkg3"

var Inst = pkg3.GetI()

-- pkg3/x.go --
package pkg3

type I interface{}

type impl[P any] struct{
	_ byte

var instance = &impl[int]{}

func GetI() I {
	return instance

Running this prints the following:

> go run ./pkg1
types are not equal

exit status 1

The values are not equal when they should be. The pointer values are identical but the types are not.

@rogpeppe rogpeppe added the generics label Oct 31, 2021
Copy link

@seankhliao seankhliao commented Oct 31, 2021

is this the same as #49241 ?

Copy link

@mvdan mvdan commented Oct 31, 2021

I think it's the same issue, but @rogpeppe wrote a minimal reproducer, so perhaps this is still useful. cc @randall77 @griesemer

Copy link

@FiloSottile FiloSottile commented Oct 31, 2021

Yep, merging into #49241 which has more discussion, but thank you @rogpeppe for preparing a much better issue and reproducer.

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

No branches or pull requests

4 participants