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: chan X(T) does not parse #39670

ianlancetaylor opened this issue Jun 17, 2020 · 1 comment

cmd/go2go: chan X(T) does not parse #39670

ianlancetaylor opened this issue Jun 17, 2020 · 1 comment


Copy link

@ianlancetaylor ianlancetaylor commented Jun 17, 2020

This initializer for c1 does not parse, and I'm not sure why. The initialize for c2 does work.

package main

type X(type T) T

var c1 = make(chan X(int))
var c2 = make(chan (X(int)))

I get

type checking failed for main
foo.go2:5:20: cannot use generic type X(type T) without instantiation
Copy link

@griesemer griesemer commented Jun 17, 2020

Note that chan x(y) is a legal type conversion (chan x)(y). Even though we are expecting a type here, for the parser make(chan X(int)) looks like an ordinary function call (it doesn't know anything about make being special) and so it expects a (non-type) expression as argument. By that logic, that expression must be a conversion. Hence you need the extra parentheses. If the parser knew to expect a type, the parentheses wouldn't be needed.

I suppose the type-checker could re-associate the expression once it knows we're dealing with the built-in make call, but that seems a bit iffy (to me).

Closing as working as intended.

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
2 participants
You can’t perform that action at this time.