Skip to content

Instantly share code, notes, and snippets.

View eernstg's full-sized avatar

Erik Ernst eernstg

  • Google
  • Aarhus, Denmark
View GitHub Profile
@eernstg
eernstg / initializing_formal_access.md
Last active November 29, 2016 11:33
Informal specification of initializing formal parameter access.

Feature: Access to Initializing Formals

This document is an informal specification of the support for access to initializing formal parameters which has been implemented in dart2js with option --initializing-formal-access, starting with commit 442fc5. In SDK 1.21 this feature is enabled by default (that is, also without the option) in all tools.

The motivation for having this feature is that it enables less verbose and less repetitive code, and it is a feature that users have frequently requested.

Recall that an initializing formal parameter is a parameter to a generative constructor whose declaration is on the form this.x for some identifier x (possibly with a type annotation as in int this.x or bool this.x(int y)). At call sites this kind of parameter is passed just like other parameters, but its name (here: x) must be the name of a field, and that field is implicitly initialized to the

@eernstg
eernstg / assert_expression.md
Last active August 29, 2016 08:18
Informal specification of assert statements with general expressions.

Feature: General expressions in assert

The language specification (Aug 19, 2015) states that an assert statement contains a parenthesized conditionalExpression. This feature changes assert to use a plain expression instead.

The motivation for having a conditionalExpression rather than a general expression in this syntactic location is not discussed in the specification, but it is likely to be a kind of safety device: A conditionalExpression covers only a subset of all expressions, and in particular it does not include assignments. An example which is often mentioned is that assert(x = 1) will be prevented syntactically, and the programmer may then note the error and change it to the more likely assert(x == 1).

However, the language specification takes different approaches in other, similar situations: An if statement, while statement, and do .. while statement all accept a general expression as the condition, whereas an argument to logical operators such as && and || must be