Skip to content
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

cmd/go2go: type inference doesn't work when casting to generic type #39866

Closed
arl opened this issue Jun 25, 2020 · 1 comment
Closed

cmd/go2go: type inference doesn't work when casting to generic type #39866

arl opened this issue Jun 25, 2020 · 1 comment

Comments

@arl
Copy link
Contributor

arl commented Jun 25, 2020

What version of Go are you using (go version)?

dev.go2go branch

go version devel +4dfbf5ab9c Thu Jun 25 02:57:14 2020 +0000 linux/amd64

Does this issue reproduce with the latest release?

Tried with latest commit dev.go2go branch.

What did you do?

package main

type stack(type T) []T

func main() {
	slice := []int{}

	_ = stack(slice) // Error: slice (variable of type []int) is not a type
	// _ = stack(int)(slice) // Ok
}

https://go2goplay.golang.org/p/jACGE-qTJ5L

What did you expect to see?

Type inference to work when casting to generic type though to be fair I couldn't find anything related to that specific point in the design draft.

What did you see instead?

I had to provide the type parameter, then it worked.

@ianlancetaylor
Copy link
Contributor

In the current design draft type inference only works for function calls, not for type conversions. So this is working as expected.

In order to add this feature to the design draft I'd like to see some realistic code that would use it. It strikes me as being likely to be more confusing than readable.

@golang golang locked and limited conversation to collaborators Jun 25, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants