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: generic function instantiated with wrong type #48253

Closed
korzhao opened this issue Sep 8, 2021 · 2 comments
Closed

cmd/compile: generic function instantiated with wrong type #48253

korzhao opened this issue Sep 8, 2021 · 2 comments
Labels
Milestone

Comments

@korzhao
Copy link
Contributor

@korzhao korzhao commented Sep 8, 2021

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

go tip 1.18

$ go version

Does this issue reproduce with the latest release?

Yes

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

go env Output
$ go env

What did you do?

package main

import (
	"fmt"
	"reflect"
)

type A[T any] struct {
	B[int]
}
type B[T any] struct {
}
func (b B[T]) Bat() {
	t := new(T)
	fmt.Println(reflect.TypeOf(t).String())
}

type Foo struct {
	A[string]
}
func main() {
	Foo{}.A.Bat()
	Foo{}.A.B.Bat()
}

What did you expect to see?

*int
*int

What did you see instead?

*string
*int
@cuonglm
Copy link
Member

@cuonglm cuonglm commented Sep 8, 2021

Unified IR works right:

$ GOEXPERIMENT=unified go run p.go
*int
*int

Loading

@cuonglm cuonglm added this to the Go1.18 milestone Sep 8, 2021
@gopherbot
Copy link

@gopherbot gopherbot commented Sep 8, 2021

Change https://golang.org/cl/348549 mentions this issue: cmd/compile: fix wrong instantinated type for embedded receiver

Loading

@gopherbot gopherbot closed this in 2481f6e Sep 9, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
3 participants