You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
[QoI] Improve cryptic error message due to accidental semicolon #352
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.
g: () = { }
f: () = {
for v* | all next log() do :(e) = {
foo();
bar*;
};
g();
}
Commands:
cppfront x.cpp2
Expected result: A diagnostic indicating to remove accidental semicolon.
Actual result and error:
x.cpp2(2,9): error: ill-formed initializer (at '{')
x.cpp2(2,1): error: unexpected text at end of Cpp2 code section (at 'f')
x.cpp2(1,0): error: parse failed for section starting here
The same error message, error: unexpected text at end of Cpp2 code section (at 'main'). In addition to the name of the declaration, if possible, the line's tail of the unexpected text could be printed, e.g.
main.cpp2(2,1): error: unexpected text at end of Cpp2 code section for 'main'
main.cpp2(3,11): error: ... at 'x;'
With #358 (comment) in mind, I think I know what's going on. Copying from the OP:
g: () = { }
f: () = {
for v* | all next log() do :(e) = {
foo();
bar*;
};
g();
}
x.cpp2(2,9): error: ill-formed initializer (at '{')
x.cpp2(2,1): error: unexpected text at end of Cpp2 code section (at 'f')
x.cpp2(1,0): error: parse failed for section starting here
f doesn't match any declaration: x.cpp2(2,1): error: unexpected text at end of Cpp2 code section (at 'f').
The preceding error is barely closer to the offending ;: x.cpp2(2,9): error: ill-formed initializer (at '{').
When I watched the talk that unveiled cppfront and came to try it out, more than a few times I wished the error messages were more telling. As a C++ programmer, I guessed it wouldn't want to go down the path of template error messages.
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.
For the OP, I think it should generally be possible to additionally diagnose something like this:
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.
Activity
JohelEGP commentedon Apr 11, 2023
I got curious about how
cppfrontwould handle$in identifiers: https://godbolt.org/z/9WaejfYas.The same error message,
error: unexpected text at end of Cpp2 code section (at 'main'). In addition to the name of the declaration, if possible, the line's tail of the unexpected text could be printed, e.g.JohelEGP commentedon Apr 11, 2023
With #358 (comment) in mind, I think I know what's going on. Copying from the OP:
fdoesn't match any declaration:x.cpp2(2,1): error: unexpected text at end of Cpp2 code section (at 'f').;:x.cpp2(2,9): error: ill-formed initializer (at '{').When I watched the talk that unveiled
cppfrontand came to try it out, more than a few times I wished the error messages were more telling. As a C++ programmer, I guessed it wouldn't want to go down the path of template error messages.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.
For the OP, I think it should generally be possible to additionally diagnose something like this:
filipsajdak commentedon Apr 11, 2023
@JohelEGP I have made some improvements in diagnostics regarding semicolons. I am running tests - it there will be no impact I will push it.
JohelEGP commentedon Apr 12, 2023
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.
filipsajdak commentedon Apr 12, 2023
I have pushed the PR: #362
filipsajdak commentedon Apr 12, 2023
After my PR the following code:
produces:
Add diagnostics for bad semicolons errors, closes #352 (#362)
Add diagnostics for bad semicolons errors, closes hsutter#352 (hsutte…