Skip to content

Specify that initializerExpression cannot be a function literal #866

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

Closed
wants to merge 4 commits into from

Conversation

eernstg
Copy link
Member

@eernstg eernstg commented Mar 3, 2020

Cf. dart-lang/sdk#11509, it has been a compile-time error since 2013 for an <initializerExpression> (that is, an expression that occurs to the right of = in an initializer list) to be a function literal. This PR finally puts that into the language specification.

Given that tools have rejected such function literals for several years, it is not a breaking change, and it requires no updates to implementations.

This resolves issue #865.

@eernstg
Copy link
Member Author

eernstg commented Mar 3, 2020

Review responses uploaded, PTAL.

@lrhn lrhn self-requested a review March 4, 2020 07:59
(\ref{notation})
of an \synt{initializerExpression} $e$,
unless it occurs inside a subterm of $e$ which is of the form
\syntax{`(' <expression> `)'}.
Copy link
Member

@lrhn lrhn Mar 4, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

HOWEVER (ahem), that's probably also not precise enough, now that I got to think about it.

We do allow some function expressions that are not inside parentheses, as long as they are inside something.
Being "inside" can be inside a collection literal or string interpolation, or occurring as a function call argument, which are still clearly delimited, but not by a parenthesized expression.

So, maybe we need a definition like:

A subexpression e of another expression o is said to be undelimited in o if:

  • e is o, or
  • o is an operator expression other (infix, prefix or suffix operators)
    and e is undelimited in one of the operand expressions of o other than
    the index operand of an [] or []= operator.

Then it is a compile-time error if a function expression is undelimited in the initializer expression.

Effectively, it has to be delimited on both side, before so that we know it's coming, and after so that we know when it's done.

(It is a little curious that we can figure out C() : x = a + {};, but not C() : x = a + (){};. Maybe we're not trying hard enough).

@eernstg eernstg force-pushed the specify_initializerExpression_nofun_mar20 branch from b751292 to bcf5602 Compare May 13, 2020 15:11
@eernstg eernstg closed this Apr 22, 2023
@eernstg eernstg deleted the specify_initializerExpression_nofun_mar20 branch April 22, 2023 10:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants