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: more clever syntax error reporting #5129

Open
btracey opened this issue Mar 26, 2013 · 10 comments

Comments

@btracey
Copy link
Contributor

commented Mar 26, 2013

Using the go 1.0.3 compiler, the code at http://play.golang.org/p/mSSyjMd_MU gives a
syntax error on line 15 that there is an unexpected ), while the actual error is that
there is a missing } on line 10. In this specific case, hypothetically the compiler
could realize the error is before line 15, because there are two return statements (line
10 and 12) otherwise. 

I imagine finding the "true" location of the syntax error in the general case
is hard to do, but I figured I would document the behavior in case something could be
done.
@bradfitz

This comment has been minimized.

Copy link
Member

commented Jun 18, 2013

Comment 2:

Labels changed: removed priority-triage.

Status changed to Accepted.

@btracey

This comment has been minimized.

Copy link
Contributor Author

commented Jun 19, 2013

Comment 3:

Here is a similar example of the same problem. It's a little contrived because there are
errors because my example uses an outside package and so there are more errors, however:
http://play.golang.org/p/CDR-Lpn2Wi
We see that the error is on line 114: syntax error: unexpected ). The real issue is that
Optimize on line 13 does not have a closed }. In between there are a constant, type, and
variable declarations, none of which would be acceptable in a function before it finally
triggers an error for unexpected ). It would be awesome if this error could be more
localized, (closer to line 13), or at least it would look at the whole code to see if
there's ever a balanced closed bracket, and then throw an error that there is no
matching closed bracket.
@rsc

This comment has been minimized.

Copy link
Contributor

commented Jul 30, 2013

Comment 4:

Labels changed: added priority-later, go1.2maybe.

@robpike

This comment has been minimized.

Copy link
Contributor

commented Aug 16, 2013

Comment 5:

Unlikely to happen in 1.2. Low priority.

Labels changed: added go1.3maybe, removed go1.2maybe.

@robpike

This comment has been minimized.

Copy link
Contributor

commented Aug 20, 2013

Comment 6:

Labels changed: removed go1.3maybe.

@btracey

This comment has been minimized.

Copy link
Contributor Author

commented Aug 27, 2013

Comment 7:

Another example it would be nice to change
http://play.golang.org/p/Q7-VnoRnEH
The error in Main() is reported before the error about Foo. In my actual code, Foo was
called a bunch so the error to Foo got buried
@btracey

This comment has been minimized.

Copy link
Contributor Author

commented Oct 24, 2013

Comment 8:

Another:
http://play.golang.org/p/OE16PMdDTY
The actual error is typing "type" instead of "func" for what is supposed to be the error
method call. Saying something like "expected semicolon or newline after type declaration
block" would trigger "Huh? That's not a type declaration block... oh wait"
@rsc

This comment has been minimized.

Copy link
Contributor

commented Nov 27, 2013

Comment 9:

Labels changed: added go1.3maybe.

@rsc

This comment has been minimized.

Copy link
Contributor

commented Dec 4, 2013

Comment 10:

Labels changed: added release-none, removed go1.3maybe.

@rsc

This comment has been minimized.

Copy link
Contributor

commented Dec 4, 2013

Comment 11:

Labels changed: added repo-main.

@rsc rsc added this to the Unplanned milestone Apr 10, 2015

@rsc rsc changed the title cmd/gc: more clever syntax error reporting cmd/compile: more clever syntax error reporting Jun 8, 2015

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
4 participants
You can’t perform that action at this time.