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: spurious error for missing argument for channel send within go func #33386
Comments
The error on L15 is the correct one. For eg., something like this is valid Go code. func main() {
send := make(chan int)
go func() {
// True error on line below. Missing value to send
send <-
10 }()
fmt.Println(<-send)
} Leaving upto @griesemer and @mdempsky to see if something can be done about L12. |
As @agnivade points out, Go's syntax allows newlines between the But we could maybe recognize cases like this somehow and emit a "missing expression" error instead? As for the error on line 12, off hand I don't know what's causing that. I'm guessing error recovery gone wrong. @griesemer might have ideas on how to address that, and whether it's worthwhile. |
I agree that the error on line 15 is correct. The error on line 12 is because the parser skips the closing '}' and then gets out of sync. Fix forthcoming. The correct error message already says "expecting expression" which is close to "missing expression" (but a bit less definitive). I filed #33415 as a reminder. |
@mdempsky / @griesemer what if the parser were to recognize it checked the next line for an expression and did not find one and then decrement the line number in the error message? Again, for any of this let me know if you'd like a PR, I've been interested in contributing |
@MaerF0x0 It's not so simple in general. For one, there could be arbitrary many empty lines before the closing '}'. There could be comments, also arbitrary many. One could record the last valid token perhaps, and then use the position immediately after that token. But if that token is followed by comments than it's weird to get an error message before that comment. We provide the error when we see the first token that is unexpected. That is simple, sensible, consistent, and expected by many tests. A single slightly unfortunate case is not a good reason to change that. Generally, good error reporting by a recursive-descent parser is more of an art than a science. The fix here is simple I believe - I just need to test it a bit more before sending it out. |
Change https://golang.org/cl/188502 mentions this issue: |
…ession Don't skip closing parentheses of any kind after a missing expression. They are likely part of the lexical construct enclosing the expression. Fixes golang#33386. Change-Id: Ic0abc2037ec339a345ec357ccc724b7ad2a64c00 Reviewed-on: https://go-review.googlesource.com/c/go/+/188502 Reviewed-by: Matthew Dempsky <mdempsky@google.com>
…ession Don't skip closing parentheses of any kind after a missing expression. They are likely part of the lexical construct enclosing the expression. Fixes golang#33386. Change-Id: Ic0abc2037ec339a345ec357ccc724b7ad2a64c00 Reviewed-on: https://go-review.googlesource.com/c/go/+/188502 Reviewed-by: Matthew Dempsky <mdempsky@google.com>
What version of Go are you using (
go version
)?Does this issue reproduce with the latest release?
1.12.7 is the latest brew will install, lmk if I need the patch.
What operating system and processor architecture are you using (
go env
)?go env
OutputWhat did you do?
When attempting to send on a channel within a
go func() {...}
call , but missing the value to sendgo build
is reporting 2 errors on other lines which are not the issue.example code: https://play.golang.org/p/V7I7f9tc_17
What did you expect to see?
a single error pointing to L14 of missing expression to send
Hypothetically
What did you see instead?
./prog.go:12:5: expression in go must be function call
./prog.go:15:2: syntax error: unexpected }, expecting expression
LMK if help wanted I'd love to contribute
The text was updated successfully, but these errors were encountered: