Skip to content
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ Author: Erik Ernst

Status: Accepted

Version: 1.12
Version: 1.13

Experiment flag: declaring-constructors

Expand Down Expand Up @@ -191,10 +191,12 @@ that the instance variable declaration which is induced by this declaring
constructor parameter is `final`.

In the case where the declaration is an `extension type`, the modifier
`final` on the representation variable can be specified or omitted. Note
that an extension type declaration is specified to use a primary
constructor (it is not supported to declare the representation variable
using a normal instance variable declaration):
`final` on the representation variable can be specified or omitted. It is
an error to specify the modifier `var` on the representation variable.

An extension type declaration is specified to use a primary constructor (it
is not supported to declare the representation variable using a normal
instance variable declaration):

```dart
// Using a primary constructor.
Expand Down Expand Up @@ -745,6 +747,12 @@ main() {
}
```

It is a compile-time error if an assignment to a primary parameter occurs
in the initializing expression of a non-late instance variable, or in the
initializer list of the body part of a primary constructor.

*This includes expressions like `p++` where the assignment is implicit.*

The following errors apply to formal parameters of a primary constructor.
Let _p_ be a formal parameter of a primary constructor in a class, mixin
class, enum, or extension type declaration _D_ named `C`:
Expand Down Expand Up @@ -840,15 +848,16 @@ positional or named parameter remains optional; if it has a default value
unchanged from _L_ to _L2_ *(this is a plain, non-declaring parameter)*.
- Otherwise, a formal parameter (named or positional) of the form `var T p`
or `final T p` where `T` is a type and `p` is an identifier is replaced
in _L2_ by `this.p`, along with its default value, if any. Next, a
semantic instance variable declaration corresponding to the syntax `T p;`
or `final T p;` is added to _D2_. It includes the modifier `final` if the
parameter in _L_ has the modifier `final` and _D_ is not an `extension
type` decaration; if _D_ is an `extension type` declaration then the name
of `p` specifies the name of the representation variable. In all cases, if
`p` has the modifier `covariant` then this modifier is removed from the
parameter in _L2_, and it is added to the instance variable declaration
named `p`.
in _L2_ by `this.p`, along with its default value, if any. If the
parameter has the modifier `var` and _D_ is an extension type declaration
then a compile-time error occurs. Otherwise, a semantic instance variable
declaration corresponding to the syntax `T p;` or `final T p;` is added
to _D2_. It includes the modifier `final` if the parameter in _L_ has the
modifier `final` and _D_ is not an `extension type` decaration; if _D_ is
an `extension type` declaration then the name of `p` specifies the name
of the representation variable. In all cases, if `p` has the modifier
`covariant` then this modifier is removed from the parameter in _L2_, and
it is added to the instance variable declaration named `p`.

If there is an initializer list following the formal parameter list _L_
then _k2_ has an initializer list with the same elements in the same order.
Expand Down Expand Up @@ -899,6 +908,11 @@ of declaration, and the constructor might be non-const).

### Changelog

1.13 - November 25, 2025

* Specify that assignments to primary parameters in initialization code is
an error.

1.12 - November 6, 2025

* Eliminate in-body declaring constructors. Revert to the terminology where
Expand Down