Closed zeebo closed 4 years ago
Looks like the translator somehow substituted the underlying type for the defined type.
This kind of thing is a bug in the translation tool. Basically, the code passed the type checker, but the generated Go-without-generics code is somehow using the wrong type.
Although I've been working on similar bug reports, and this code now fails in a completely different way. But it's still a bug in the translation tool.
This should be fixed now in the dev.go2go branch.
Thanks for the test case.
Change https://golang.org/cl/238797 mentions this issue: [dev.go2go] go/go2go: add type arguments to type instantiation
What version of Go are you using (
go version
)?go2go playground
What did you do?
https://go2goplay.golang.org/p/LDEr36y6IUr
Source
``` package main type Func(type A, B) interface { Run(A) B } ////// type Pair(type A, B) struct { L A R B } ////// type Compose(type A, B, C) struct { L Func(A, B) R Func(B, C) } func (p Compose(A, B, C)) Run(in A) C { return p.R.Run(p.L.Run(in)) } ////// type Dup(type A) struct{} func (d Dup(A)) Run(in A) Pair(A, A) { return Pair(A, A){ L: in, R: in, } } ////// func main() { _ = Compose( int, Pair(int, int), Pair(Pair(int, int), Pair(int, int)), ){ L: Dup(int){}, R: Dup(Pair(int, int)){}, } } ```
What did you expect to see?
No compiler error and no output
What did you see instead?
A large error message
This seemed more important because it happens after translation, which possibly indicates a soundness hole in the type checker? Though, I do believe the program is well typed, so maybe just a bug in the translation.