-
-
Notifications
You must be signed in to change notification settings - Fork 192
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
unexpected 'await' keyword on function declaration #1187
base: master
Are you sure you want to change the base?
Conversation
[[qljs::message("Unexpected 'await' keyword on function declaration. Maybe you meant 'async'?", | ||
ARG(await_keyword))]] // |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You should follow the syntactic style of existing diagnostics (like E0178) instead:
[[qljs::message("Unexpected 'await' keyword on function declaration. Maybe you meant 'async'?", | |
ARG(await_keyword))]] // | |
[[qljs::message("unexpected 'await' keyword on function declaration; maybe you meant 'async'?", | |
ARG(await_keyword))]] // |
@@ -1,6 +1,7 @@ | |||
// Copyright (C) 2020 Matthew "strager" Glazar | |||
// See end of file for extended copyright information. | |||
|
|||
#include <cstdio> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: Undo.
this->diag_reporter_->report( | ||
Diag_Unexpected_Await_On_Function_Declaration{ | ||
.await_keyword = await_token.span()}); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Must fix: Your special handling of function
is wrong in a few ways:
await function foo() {}();
is parsed incorrectly. You have a test for it, buttest_parse_and_visit_statement
doesn't assert that the whole input is parsed. (It probably should... I should fix that.) This code is parsingawait function foo() {}
as a statement, leaving();
as a second statement (which is wrong!).await function () {}
falsely reports E0061 ("missing name in function statement").
Also, adding code here in parse_and_visit_expression doesn't catch mistakes such as the following:
foo(await function() {
});
parse_await_expression
is probably a better place to put your logic.
#413