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

Closed
ianlancetaylor opened this issue Jun 17, 2020 · 1 comment
Closed

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

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

Comments

@ianlancetaylor
Copy link
Contributor

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
@ianlancetaylor ianlancetaylor 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
@ianlancetaylor ianlancetaylor added this to the Unreleased milestone Jun 17, 2020
@griesemer
Copy link
Contributor

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.

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

3 participants