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/compile: imperfect compile error message #44321

Open
go101 opened this issue Feb 17, 2021 · 2 comments
Open

cmd/compile: imperfect compile error message #44321

go101 opened this issue Feb 17, 2021 · 2 comments
Labels
compiler/runtime Issues related to the Go compiler and/or runtime. NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Milestone

Comments

@go101
Copy link

go101 commented Feb 17, 2021

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

$ go version
go version go1.16 linux/amd64

Does this issue reproduce with the latest release?

Yes

What did you do?

  package main

  func main() {
    var a, b = 1, -2
    println(a<-b)
  }

What did you expect to see?

syntax error: a is not channel, unexpected <-

What did you see instead?

syntax error: unexpected <-, expecting comma or )

BTW, go fmt doesn't work for much code which fails to compile.
But I think it should work here.

@griesemer
Copy link
Contributor

a <- b is a send statement, not an expression. The error message seems quite reasonable. The parser usually doesn't comment on what type a variable is, either.

@griesemer griesemer added this to the Unplanned milestone Feb 17, 2021
@griesemer griesemer added the NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. label Feb 17, 2021
@go101
Copy link
Author

go101 commented Feb 17, 2021

I understand. But the message doesn't make people realize the real cause at the first time.
And, the second half "expecting comma or )" is not very accurate. Comma and ) are not the only possibilities.

@gopherbot gopherbot added the compiler/runtime Issues related to the Go compiler and/or runtime. label Jul 13, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
compiler/runtime Issues related to the Go compiler and/or runtime. 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