undefined: T in func x[T](p *T)(**T) when x[*T](x[T](a))
Hello the following program fails to compile https://play.folang.org/p/2XxLi_ukWR5
package main
func x[T](p *T)(**T){
return &p
}
func y[T](a *T){
x[*T](x[T](a))
}
func main() {
}
Closely related form:
package main
func dontrunthisfunction[T](p *T){
dontrunthisfunction[*T](&p)
}
func main() {
}
@go-li thank you for reporting this.
~~The issue lies with pointer dereference expressions of the form *T where T is a type parameter. After spending some time thinking about it, I believe these kinds of expressions should not be allowed and the compiler should report an error. (The current error message obviously doesn't make much sense so I would like to improve it by catching the issue earlier on in the type-checker).~~ Edit: I'm sorry, I was mistaken. The code you shared should not have anything that gets interpreted as a dereference expression. I'll investigate further and fix the issue as soon as I get a chance.
Related to https://github.com/albrow/fo/issues/27.
Taking a closer look at your example:
func dontrunthisfunction[T](p *T){
dontrunthisfunction[*T](&p)
}
Here, *T is a form of polymorphic recursion that will probably be disallowed by the type checker moving forward.