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: generic types as return parameters breakages #39674

Closed
carnott-snap opened this issue Jun 18, 2020 · 3 comments
Closed

cmd/go2go: generic types as return parameters breakages #39674

carnott-snap opened this issue Jun 18, 2020 · 3 comments

Comments

@carnott-snap
Copy link

What did you do?

https://go2goplay.golang.org/p/5qj5r_lSwoK
https://go2goplay.golang.org/p/J9UMhLZJZyH

What did you expect to see?

{true}

What did you see instead?

prog.go2:16:67: expected operand, found 'return'

and

prog.go2:11:41: mixed named and unnamed function parameters (and 1 more errors)

Did you find a workaround?

In both cases adding names to the parameters fixed things, so it seems like the parser is broken:

https://go2goplay.golang.org/p/5sJXISHuwAb
https://go2goplay.golang.org/p/9TgTCD5SLnZ

@martisch
Copy link
Contributor

martisch commented Jun 18, 2020

Duplicate of #39655:

Quote:

Alternatively, you need to write (_ Result(T)) or ((Result(T))). The reason is that (Result(T)) is interpreted as (Result (T)), i.e., the result is named Result and is of parenthesized type (T), for backwards-compatibility.

https://go.googlesource.com/proposal/+/refs/heads/master/design/go2draft-type-parameters.md#using-generic-types-as-unnamed-function-parameter-types

@gertcuykens
Copy link
Contributor

gertcuykens commented Jun 18, 2020

Also Duplicate of #39656

PS Because of how many people run into this, can there be at least one of them open to investigate if the compiler error message can be improved in all does cases? I understand if it isn't possible and maybe go vet can help here?

@carnott-snap
Copy link
Author

There were two syntaxes that I came across that did not work. The second seems covered by #39656, but the first seems like a bug, since this fails (but only for closures):

f := func(b bool) Box(string) { return Box(string){strconv.FormatBool(b)} }

@golang golang locked and limited conversation to collaborators Jun 20, 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

4 participants