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: problem with unnamed function parameter #39656

aitva opened this issue Jun 17, 2020 · 3 comments

cmd/go2go: problem with unnamed function parameter #39656

aitva opened this issue Jun 17, 2020 · 3 comments


Copy link

@aitva aitva commented Jun 17, 2020

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

I have been experimenting with

What did you do?

I built a program using generic and unnamed function parameter.

type Endpoint(type A, B) func(context.Context, A) (B, error)

type Middleware(type A, B) func(Endpoint(A, B)) Endpoint(A, B)

func Chain(type A, B)(middlewares ...Middleware(A, B)) Middleware(A, B) {
	return func(next Endpoint(A, B)) Endpoint(A, B) {
		for i := len(middlewares) - 1; i > 0; i-- {
			next = middlewares[i](next)
		return next

What did you expect to see?

A successful build.

What did you see instead?

A build error:

prog.go2:9:43: expected ')', found ',' (and 1 more errors)

It can be fixed by adding a name to the Middleware parameter:

type Middleware(type A, B) func(next Endpoint(A, B)) Endpoint(A, B)

But then it fails in the Chain function with:

prog.go2:13:3: expected operand, found 'for' (and 3 more errors)

Here is a link to a working version with all the unnamed parameter named :

Copy link

@andybons andybons commented Jun 17, 2020

@andybons andybons added this to the Unplanned milestone Jun 17, 2020
Copy link

@benjaminjkraft benjaminjkraft commented Jun 17, 2020

I think the first part of this is one of the parsing ambiguities described in the design draft, and then the second is #39654 (a new but related parsing ambiguity).

Copy link

@griesemer griesemer commented Jun 17, 2020

This is indeed the parsing ambiguity described already; this code works. Again, there's only this one issue here (once in the parameter list of the Middleware function, and once in the result of the Chain function).

Closing is working as intended.

Again, please know that we're likely going to change this as this ambiguity is biting a lot of people.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
4 participants
You can’t perform that action at this time.