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

go/format: printer omits parens around type in T(x) in synthetic AST #63362

Closed
adonovan opened this issue Oct 4, 2023 · 2 comments
Closed

go/format: printer omits parens around type in T(x) in synthetic AST #63362

adonovan opened this issue Oct 4, 2023 · 2 comments
Assignees

Comments

@adonovan
Copy link
Member

adonovan commented Oct 4, 2023

https://go.dev/play/p/p5A4mFaqogQ creates a synthetic syntax tree representing <-(<-chan int)(nil). The go/format printer renders this as <-<-chan int(nil), which parses to a different tree--a receive of a receive--that doesn't type check because the channel value is int. (If instead we had used <-<-chan chan int(nil), the result would type check but would have a different meaning.) The parser creates a ParenExpr around the type so the problem doesn't show up in gofmt, but only in refactoring tools that create syntax trees programmatically.

I think this is a bug in the printer, and that it should emit parens.

@adonovan adonovan self-assigned this Oct 4, 2023
@gopherbot
Copy link

Change https://go.dev/cl/532556 mentions this issue: go/printer: parenthesize type in <-((<-chan int)(nil))

@gopherbot
Copy link

Change https://go.dev/cl/532576 mentions this issue: internal/refactor/inline: work around channel type misformatting

gopherbot pushed a commit to golang/tools that referenced this issue Oct 5, 2023
This change adds parens around the type in T(x) conversions
where T is a receive-only channel type, as previously it
would be misformatted as a receive of a receive.

Updates golang/go#63362

Change-Id: I935b5598d4bc3ea57dd52964e8b02005f5e6ef72
Reviewed-on: https://go-review.googlesource.com/c/tools/+/532576
Reviewed-by: Robert Findley <rfindley@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants