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: parse error on multiple type parameters inside a type parameter #40021

Closed
beoran opened this issue Jul 3, 2020 · 2 comments
Closed

cmd/go2go: parse error on multiple type parameters inside a type parameter #40021

beoran opened this issue Jul 3, 2020 · 2 comments

Comments

@beoran
Copy link

@beoran beoran commented Jul 3, 2020

On the playground this fails to compile in ThisDoesNot with prog.go2:20:7: expected ')', found ',' (and 1 more errors):

https://go2goplay.golang.org/p/fDM1HQlOGUF

package main

import (
	"fmt"
)

type Any = interface{}
type Super(type S) interface {
   type S
} 

type N(type S Any, X Super(S)) Any
type L(type X) Any

type ThisWorks(type S,X) interface {
   N(S,X)
} 

type ThisDoesNot(type S Any, X Super(S)) interface {
	L(N(S,X))
}

func main() {
	fmt.Prinf("OK")
}

I would expect it to compile though. Is this so?

@beoran beoran changed the title cmd/gotogo: parse error on multiple type parameters inside a type parameter cmd/go2togo: parse error on multiple type parameters inside a type parameter Jul 3, 2020
@beoran beoran changed the title cmd/go2togo: parse error on multiple type parameters inside a type parameter cmd/go2go: parse error on multiple type parameters inside a type parameter Jul 3, 2020
@ianlancetaylor
Copy link
Contributor

@ianlancetaylor ianlancetaylor commented Jul 3, 2020

In this code

type ThisDoesNot(type S Any, X Super(S)) interface {
	L(N(S,X))
}

L(N(S, X)) looks like a method definition. You need to write this as

type ThisDoesNot(type S Any, X Super(S)) interface {
	(L(N(S,X)))
}

Yes, this is awkward. This is mentioned at https://go.googlesource.com/proposal/+/refs/heads/master/design/go2draft-type-parameters.md#embedding-an-instantiated-interface-type .

@beoran
Copy link
Author

@beoran beoran commented Jul 3, 2020

Ah, I see. This is indeed an akward syntax. Please consider coming up with something better. Also, a better parse error would be useful here.

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

Successfully merging a pull request may close this issue.

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