Skip to content
This repository has been archived by the owner on Sep 20, 2022. It is now read-only.

undefined: T in func x[T](p *T)(**T) when x[*T](x[T](a)) #23

Open
go-li opened this issue Jul 31, 2018 · 3 comments
Open

undefined: T in func x[T](p *T)(**T) when x[*T](x[T](a)) #23

go-li opened this issue Jul 31, 2018 · 3 comments
Assignees
Labels
bug Something isn't working

Comments

@go-li
Copy link

go-li commented Jul 31, 2018

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() {
}
@go-li
Copy link
Author

go-li commented Aug 1, 2018

Closely related form:

package main

func dontrunthisfunction[T](p *T){
	dontrunthisfunction[*T](&p)
}

func main() {
}

@albrow albrow added the bug Something isn't working label Aug 3, 2018
@albrow albrow self-assigned this Aug 3, 2018
@albrow
Copy link
Owner

albrow commented Aug 3, 2018

@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.

@albrow
Copy link
Owner

albrow commented Nov 9, 2018

Related to #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.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants