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

Comments

@go101
Copy link

@go101 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

@griesemer griesemer commented Feb 17, 2021

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
@go101
Copy link
Author

@go101 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.

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