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

Async Function Definitions: FormalParameters [?Await], contradicts with text #978

Closed
marjakh opened this Issue Aug 17, 2017 · 3 comments

Comments

Projects
None yet
2 participants
@marjakh
Contributor

marjakh commented Aug 17, 2017

Link:
14.6 Async Function Definitions

In the AsyncFunctionDeclaration production, FormalParameters are parameterized with [~Yield, ?Await]: yield is allowed as an identifier and await is allowed as an identifier iff the parent production allows it (i.e., if the async function occurs at top level, await would be allowed as an identifier).

Note 1 says:

"When Script is the syntactic goal symbol, await may be parsed as an identifier when the [Await] parameter is absent. This includes the following contexts:

  • Anywhere outside of an AsyncFunctionBody or FormalParameters of an AsyncFunctionDeclaration or AsyncFunctionExpression.
  • ..."

which contradicts with the productions.

The production probably should have FormalParameters parameterized with [~Yield, +Await].

In the AsyncFunctionExpression production, FormalParameters are parameterized with [~Yield, +Await] as expected.

marjakh pushed a commit to marjakh/ecma262 that referenced this issue Aug 17, 2017

Marja Hölttä
Normaitve: Fix [?Await] in AsyncFuntionDeclarations' FormalParameters (
…tc39#978)

According to the note below, this was the intention. Also makes
AsyncFunctionDeclaration consistent with AsyncFunctionExpression in this regard.

marjakh pushed a commit to marjakh/ecma262 that referenced this issue Aug 17, 2017

Marja Hölttä
Normative: Fix [?Await] in AsyncFuntionDeclarations' FormalParameters (
…tc39#978)

In the AsyncFunctionDeclaration production, FormalParameters were parameterized
with [?Await] instead of [+Await]. According to the note below, the intention
was [+Await].

This also makes AsyncFunctionDeclaration consistent with AsyncFunctionExpression
in this regard.

marjakh pushed a commit to marjakh/ecma262 that referenced this issue Aug 17, 2017

Marja Hölttä
Normative: Fix [?Await] in async function FormalParameters (tc39#978)
In the AsyncFunctionDeclaration production, FormalParameters were parameterized
with [?Await] instead of [+Await]. According to the note below, the intention
was [+Await].

This also makes AsyncFunctionDeclaration consistent with AsyncFunctionExpression
in this regard.
@littledan

This comment has been minimized.

Show comment
Hide comment
@littledan

littledan Aug 17, 2017

Member

The change seems to reflect the behavior of V8, ChakraCore, SpiderMonkey and JSC:

$ eshost -e "async function(await) {}"
#### jsc
SyntaxError: Can't use 'await' as a parameter name in an async function.

#### chakracore
SyntaxError: The use of a keyword for an identifier is invalid

#### spidermonkey
SyntaxError: missing formal parameter:

#### d8
SyntaxError: Unexpected reserved word

Should we give similar treatment to CoverCallExpressionAndAsyncArrowHead? It looks like that also takes Await as a parameter, but similarly, four implementations seem to consistently reject Await.

Since this is such consistent consensus among implementations, and the await parameter would be unusable if it were definable, and the patch also matches the grammar for single-parameter arrow functions (which ban async await => { /* ... */ } , I think we should definitely merge this patch.

Member

littledan commented Aug 17, 2017

The change seems to reflect the behavior of V8, ChakraCore, SpiderMonkey and JSC:

$ eshost -e "async function(await) {}"
#### jsc
SyntaxError: Can't use 'await' as a parameter name in an async function.

#### chakracore
SyntaxError: The use of a keyword for an identifier is invalid

#### spidermonkey
SyntaxError: missing formal parameter:

#### d8
SyntaxError: Unexpected reserved word

Should we give similar treatment to CoverCallExpressionAndAsyncArrowHead? It looks like that also takes Await as a parameter, but similarly, four implementations seem to consistently reject Await.

Since this is such consistent consensus among implementations, and the await parameter would be unusable if it were definable, and the patch also matches the grammar for single-parameter arrow functions (which ban async await => { /* ... */ } , I think we should definitely merge this patch.

@marjakh

This comment has been minimized.

Show comment
Hide comment
@marjakh

marjakh Aug 18, 2017

Contributor

I don't think we should change this production:

CoverCallExpressionAndAsyncArrowHead[Yield, Await] :
MemberExpression[?Yield, ?Await] Arguments[?Yield, ?Await]

because we want to allow await in the "not async arrow func" case.

The "Supplemental Syntax" below CoverCallExpressionAndAsyncArrowHead already says:

"When processing an instance of the production AsyncArrowFunction: CoverCallExpressionAndAsyncArrowHead [no LineTerminator here] => AsyncConciseBody the interpretation of CoverCallExpressionAndAsyncArrowHead is refined using the following grammar:

AsyncArrowHead :
async [no LineTerminator here] ArrowFormalParameters [~Yield, +Await]"

and that already forbids await there.

So I don't think anything related to CoverCallExpressionAndAsyncArrowHead needs to be changed.

Contributor

marjakh commented Aug 18, 2017

I don't think we should change this production:

CoverCallExpressionAndAsyncArrowHead[Yield, Await] :
MemberExpression[?Yield, ?Await] Arguments[?Yield, ?Await]

because we want to allow await in the "not async arrow func" case.

The "Supplemental Syntax" below CoverCallExpressionAndAsyncArrowHead already says:

"When processing an instance of the production AsyncArrowFunction: CoverCallExpressionAndAsyncArrowHead [no LineTerminator here] => AsyncConciseBody the interpretation of CoverCallExpressionAndAsyncArrowHead is refined using the following grammar:

AsyncArrowHead :
async [no LineTerminator here] ArrowFormalParameters [~Yield, +Await]"

and that already forbids await there.

So I don't think anything related to CoverCallExpressionAndAsyncArrowHead needs to be changed.

@littledan

This comment has been minimized.

Show comment
Hide comment
@littledan

littledan Aug 18, 2017

Member

Oh I see, good.

Member

littledan commented Aug 18, 2017

Oh I see, good.

@bterlson bterlson closed this in d075fe7 Aug 18, 2017

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment