-
Notifications
You must be signed in to change notification settings - Fork 18k
cmd/go2go: Failing to handle generic instances that are unknown until the run time. #42863
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
Comments
The generics design draft is clear that if a generic type refers to itself, it must use the same type arguments. Likely the same restriction should be applied to generic functions, in which case this test case would generate an error in the type checker. @griesemer Any thoughts? |
Oh, right, it says "refers", not "names". Also, should not that part be talking about "instantiations of a generic type"? Strictly speaking the generic type |
Wait, does that mean that |
The restriction is on the definition of |
Oh, I think now I get what restriction on generic functions you mean: |
In any case, this code should not lead to an endless recursion. The problem should be caught at typechecking time. |
Closing as duplicate of #48098. |
What version of Go are you using (
go version
)?What operating system and processor architecture are you using (
go env
)?What did you do?
https://go2goplay.golang.org/p/NZaWIbJ5DAw (inspired by an example from http://okmij.org/ftp/Computation/typeclass.html, starting at the words "The final example deals with polymorphic recursion").
What did you expect to see?
Either that the program compiles and outputs
{{{{{test}}}}}
, or a compilation error that essentially says "All generic instantiations must be known at compile time", or even "The typeT
inwrapper[T]
is not allowed to be an instance ofwrapper[T]
", is reported.I believe a slightly modified example (https://go2goplay.golang.org/p/1TnY_eXmRQY, with
T
's bound changed fromany
tofmt.Stringer
) should not trigger "The typeT
inwrapper[T]
is not allowed to be an instance ofwrapper[T]
" error, since in this case a value of typeT
is not directly embedded intowrapper[T]
but instead an interface pointer to it is stored.What did you see instead?
The text was updated successfully, but these errors were encountered: