You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository has been archived by the owner on Sep 20, 2022. It is now read-only.
package main
type Foo[T] struct{
Field []Foo[[]T]
}
func main(){
}
The generated go is:
package main
type Foo____T struct {
Field []Foo______T
}
func main() {
}
Which results in a compile error:
$ fo run main.fo
# command-line-arguments
./main.go:4:10: undefined: Foo______T
ERROR: exit status 2
What's happening is that fo is not properly dealing with polymorphic recursion, i.e. when a polymorphic/generic type is defined which is recursive, and uses something other than the original type parameter in the recursive uses of the type. The Go 2 generics draft design mentions this case:
Their solution is to explicitly disallow it, because it makes an implementation which just specializes everything impossible. I think this is the correct solution. fo should check for this and emit a comprehensible error, rather than just spitting out broken code.
The text was updated successfully, but these errors were encountered:
@zenhack thank you for opening this issue. I agree with your proposed solution to simply disallow this case. It should be easy enough to catch in the type checker.
Given main.fo:
The generated go is:
Which results in a compile error:
What's happening is that fo is not properly dealing with polymorphic recursion, i.e. when a polymorphic/generic type is defined which is recursive, and uses something other than the original type parameter in the recursive uses of the type. The Go 2 generics draft design mentions this case:
https://go.googlesource.com/proposal/+/master/design/go2draft-contracts.md#parameterized-types
Their solution is to explicitly disallow it, because it makes an implementation which just specializes everything impossible. I think this is the correct solution. fo should check for this and emit a comprehensible error, rather than just spitting out broken code.
The text was updated successfully, but these errors were encountered: