|
44 | 44 | % Dec 2023
|
45 | 45 | % - Allow `~/` on operands of type `double` in constant expressions, aligning
|
46 | 46 | % the specification with already implemented behavior.
|
| 47 | +% - Broaden the grammar rule about `initializerExpression` to match the |
| 48 | +% implemented behavior. Specify that an initializer expression can not be |
| 49 | +% a function literal. |
47 | 50 | %
|
48 | 51 | % Nov 2023
|
49 | 52 | % - Specify that the dynamic error for calling a function in a deferred and
|
@@ -4233,13 +4236,43 @@ \subsubsection{Generative Constructors}
|
4233 | 4236 | <fieldInitializer> ::= \gnewline{}
|
4234 | 4237 | (\THIS{} `.')? <identifier> `=' <initializerExpression>
|
4235 | 4238 |
|
4236 |
| -<initializerExpression> ::= <conditionalExpression> | <cascade> |
| 4239 | +<initializerExpression> ::= \gnewline{} |
| 4240 | + <assignableExpression> <assignmentOperator> <expression> |
| 4241 | + \alt <conditionalExpression> |
| 4242 | + \alt <cascade> |
| 4243 | + \alt <throwExpression> |
4237 | 4244 | \end{grammar}
|
4238 | 4245 |
|
| 4246 | +%% TODO(eernst): When #54262 is resolved, delete the next paragraph. |
| 4247 | +%% If <expression> is changed such that it derives <functionExpression>, |
| 4248 | +%% the following error will simply be a property of the grammar rule |
| 4249 | +%% because <initializerExpression> will _not_ derive <functionExpression>. |
| 4250 | +\LMHash{}% |
| 4251 | +As a special disambiguation rule, |
| 4252 | +an \synt{initializerExpression} can not derive a \synt{functionExpression}. |
| 4253 | + |
| 4254 | +\rationale{% |
| 4255 | +This resolves a near-ambiguity: |
| 4256 | +In \code{A()\,:\,\,x\,\,=\,\,()\,\,\{\,\ldots\,\}}, |
| 4257 | +\code{x} could be initialized to the empty record, |
| 4258 | +and the block could be the body of the constructor. |
| 4259 | +Alternatively, \code{x} could be initialized to a function object, |
| 4260 | +and the constructor would then not have a body. |
| 4261 | +It would only be known which case we have when we encounter |
| 4262 | +(or do not encounter) |
| 4263 | +a semicolon at the very end. |
| 4264 | +That was considered unreadable. |
| 4265 | +Hence, parsers can commit to not parsing a function expression |
| 4266 | +in this situation. |
| 4267 | +Note that it is still possible for \synt{initializerExpression} to derive |
| 4268 | +a term that contains a function expression as a subterm, e.g., |
| 4269 | +\code{A()\,:\,\,x\,\,=\,\,(()\,\,\{\,\ldots\,\});}.% |
| 4270 | +} |
| 4271 | + |
4239 | 4272 | \LMHash{}%
|
4240 | 4273 | An initializer of the form \code{$v$ = $e$} is equivalent to
|
4241 | 4274 | an initializer of the form \code{\THIS.$v$ = $e$},
|
4242 |
| -both forms are called \Index{instance variable initializers}. |
| 4275 | +and both forms are called \Index{instance variable initializers}. |
4243 | 4276 | It is a compile-time error if the enclosing class
|
4244 | 4277 | does not declare an instance variable named $v$.
|
4245 | 4278 | It is a compile-time error unless the static type of $e$
|
@@ -8318,6 +8351,11 @@ \section{Expressions}
|
8318 | 8351 | which may affect the static type and evaluation of the expression.
|
8319 | 8352 | Every object has an associated dynamic type (\ref{dynamicTypeSystem}).
|
8320 | 8353 |
|
| 8354 | +%% TODO(eernst): <expression> should derive <functionExpression> as well, |
| 8355 | +%% the fact that it is currently derived from <primary> induces a genuine |
| 8356 | +%% and serious source of ambiguity, which makes it difficult to parse Dart |
| 8357 | +%% using anything other than a modified recursive descent parser. |
| 8358 | + |
8321 | 8359 | \begin{grammar}
|
8322 | 8360 | <expression> ::= <assignableExpression> <assignmentOperator> <expression>
|
8323 | 8361 | \alt <conditionalExpression>
|
|
0 commit comments