-
Notifications
You must be signed in to change notification settings - Fork 212
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
Conversation
Review responses uploaded, PTAL. |
(\ref{notation}) | ||
of an \synt{initializerExpression} $e$, | ||
unless it occurs inside a subterm of $e$ which is of the form | ||
\syntax{`(' <expression> `)'}. |
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.
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).
b751292
to
bcf5602
Compare
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.