-
Notifications
You must be signed in to change notification settings - Fork 17.9k
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: recursive generic interface instantiation error #65362
Comments
CC @golang/compiler, and perhaps @griesemer specifically? |
The type checker is happy with this code. Looks like a problem in the backend (backend type checker). Here's a simplified repro (playground), at tip: package main
type Vector[V any] interface {
ReadVector[V]
}
type ReadVector[V any] interface {
Comparisons[ReadVector[V], Vector[V]]
}
type Comparisons[RV, V any] interface {
Diff(RV) V
}
type VectorImpl[V any] struct{}
func (*VectorImpl[V]) Diff(ReadVector[V]) (_ Vector[V]) {
return
}
func main() {
var v1 VectorImpl[int]
var v2 Vector[int]
_ = v1.Diff(v2)
} resulting in:
@mdempsky, @randall77 any insights? |
The code looks reasonable, and I don't immediately see why it would be failing. I'd guess it's an error during runtime dictionary construction. (Cc @cuonglm because he's good at debugging these issues too.) |
@mdempsky I think this is a bad interaction when shapifying recursive instantiated type argument Because Probably we should shapifying an interface type as-is if it is fully instantiated and already has shape?
|
Change https://go.dev/cl/559656 mentions this issue: |
Go version
go version go1.21.6 linux/amd64
Output of
go env
in your module/workspace:What did you do?
I wrote the code shown below and in the following playground link: https://go.dev/play/p/d8XxoEklO6D
What did you see happen?
The compiler produced the following error:
What did you expect to see?
I expected the program to compile and print the empty Vector[int] structure value.
Of note is if you change the second generic parameter on line 11 to
Vector[int]
as well as the corresponding type on the Difference method on line then the compiler successfully finishes, and the program works as intended.I am not sure if this is relevant, but the compiler error does not list the difference method on the Vector return type of the Difference method in the error it produces. It prints this:
when I think it should print something like this (formatting added for readability):
I am guessing on the syntax of the output shown above, I am just saying what would make sense to see based on what I am already seeing, I am sure the correct output is different.
I am not sure what the rules are regarding recursive interface type definitions as shown in the example, and the issue is only compounded by the added generics.
The text was updated successfully, but these errors were encountered: