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

Closed
aitva opened this issue Jun 17, 2020 · 3 comments
Closed

cmd/go2go: problem with unnamed function parameter #39656

aitva opened this issue Jun 17, 2020 · 3 comments
Labels
FrozenDueToAge NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Milestone

Comments

@aitva
Copy link

aitva commented Jun 17, 2020

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

I have been experimenting with https://go2goplay.golang.org

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
	}
}

https://go2goplay.golang.org/p/d5Ta-AEHDQo

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 : https://go2goplay.golang.org/p/oY8ggQsH3M5

@andybons
Copy link
Member

@ianlancetaylor @griesemer

@andybons andybons added the NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. label Jun 17, 2020
@andybons andybons added this to the Unplanned milestone Jun 17, 2020
@benjaminjkraft
Copy link

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

@griesemer
Copy link
Contributor

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 subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
FrozenDueToAge NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Projects
None yet
Development

No branches or pull requests

5 participants