Skip to content

Conversation

HicaroD
Copy link
Contributor

@HicaroD HicaroD commented Jan 15, 2024

Comment on lines 3606 to 3607
[[qljs::message("Unexpected 'await' keyword on function declaration. Maybe you meant 'async'?",
ARG(await_keyword))]] //
Copy link
Collaborator

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:

Suggested change
[[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>
Copy link
Collaborator

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()});
}
Copy link
Collaborator

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, but test_parse_and_visit_statement doesn't assert that the whole input is parsed. (It probably should... I should fix that.) This code is parsing await 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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants