-
Notifications
You must be signed in to change notification settings - Fork 259
[QoI] Improve cryptic error message due to accidental semicolon #352
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
Comments
I got curious about how int x$x = 0;
main: () = {
:() = x$x;
} The same error message,
|
With #358 (comment) in mind, I think I know what's going on. Copying from the OP:
When I watched the talk that unveiled Error messages have been improving. But in particular, those with a stack of source locations, like the one above, seemed like they could do better. Now, I think it should be possible to improve the status-quo. The parser could keep a record of the furthest it got.
|
@JohelEGP I have made some improvements in diagnostics regarding semicolons. I am running tests - it there will be no impact I will push it. |
Thank you. The suggestion at #352 (comment) should work for more than semicolons. For example, #352 (comment) is not about the semicolon. The error message of #358 (comment) already does point to the offending token. |
I have pushed the PR: #362 |
After my PR the following code: int x$x = 0;
main: () = {
:() = x$x;
} produces:
|
* Add diagnostics for semicolon at the end of function This change introduce diagnostics when there is a semicolon at the end of the function body: ```cpp g: () = {}; ``` Generates: ``` error: a compound function body shall not end with a semicolon (at ';') ``` And ```cpp g: () = 42;; ``` Generates: ``` error: a short function syntax shall end with a single semicolon (at ';') ``` * Add diagnostics for semicolon at the end of for loop This change introduce diagnostics when there is a semicolon at the end of the for..do loop body: ```cpp for v* | all next log() do :(e) = { foo(); bar*; }; ``` generates: ``` error: for..do loop body shall not end with a semicolon (at ';') ``` * Add diagnostics for semicolon at the end of while body This change introduce diagnostics when there is a semicolon at the end of the while loop body: ```cpp i := 0; while i* < container.size() next i++ { std::cout << container[i] << std::endl; }; ``` generates: ``` error: while loop body shall not end with a semicolon (at ';') ``` * Add diagnostics for double semicolon at short lambda This change introduce diagnostics when there is a double semicolon at the end of the short function body for unnamed function: ```cpp l2 := :() -> int = 24;; ``` Generates: ``` error: a short function syntax shall end with a single semicolon (at ';') ``` * Add diagnostics for empty statements (extra semicolon) This change introduce diagnostics when there is a semicolon without statement ```cpp ; ``` Generates: ``` error: empty statement is not allowed - remove extra semicolon (at ';') ``` That also handles cases when there is double semicolon after a proper statemnt: ```cpp i := 0;; ``` Generates: ``` error: empty statement is not allowed - remove extra semicolon (at ';') ``` * Fix error() method that throws when done() is true When done() is true last correct token and its position is printed.
…r#362) * Add diagnostics for semicolon at the end of function This change introduce diagnostics when there is a semicolon at the end of the function body: ```cpp g: () = {}; ``` Generates: ``` error: a compound function body shall not end with a semicolon (at ';') ``` And ```cpp g: () = 42;; ``` Generates: ``` error: a short function syntax shall end with a single semicolon (at ';') ``` * Add diagnostics for semicolon at the end of for loop This change introduce diagnostics when there is a semicolon at the end of the for..do loop body: ```cpp for v* | all next log() do :(e) = { foo(); bar*; }; ``` generates: ``` error: for..do loop body shall not end with a semicolon (at ';') ``` * Add diagnostics for semicolon at the end of while body This change introduce diagnostics when there is a semicolon at the end of the while loop body: ```cpp i := 0; while i* < container.size() next i++ { std::cout << container[i] << std::endl; }; ``` generates: ``` error: while loop body shall not end with a semicolon (at ';') ``` * Add diagnostics for double semicolon at short lambda This change introduce diagnostics when there is a double semicolon at the end of the short function body for unnamed function: ```cpp l2 := :() -> int = 24;; ``` Generates: ``` error: a short function syntax shall end with a single semicolon (at ';') ``` * Add diagnostics for empty statements (extra semicolon) This change introduce diagnostics when there is a semicolon without statement ```cpp ; ``` Generates: ``` error: empty statement is not allowed - remove extra semicolon (at ';') ``` That also handles cases when there is double semicolon after a proper statemnt: ```cpp i := 0;; ``` Generates: ``` error: empty statement is not allowed - remove extra semicolon (at ';') ``` * Fix error() method that throws when done() is true When done() is true last correct token and its position is printed.
The source locations are nowhere near the semicolon. The implementation should know when a semicolon is not needed, so the error message can be more to the point.
Minimal reproducer (https://godbolt.org/z/5Eovbx4Yb):
Commands:
Expected result: A diagnostic indicating to remove accidental semicolon.
Actual result and error:
The text was updated successfully, but these errors were encountered: