Skip to content

Commit fa0db63

Browse files
committed
primary-constructors: Simplify desugaring
Splits the extension type case from the other cases. It is different enough that it is easier to read by itself, instead of as exceptions to a more complicated rule. Be more explicit about `covariant`. (Still think it shouldn't create new syntax, just a new semantic constructor.)
1 parent d5aa743 commit fa0db63

1 file changed

Lines changed: 26 additions & 18 deletions

File tree

accepted/future-releases/primary-constructors/feature-specification.md

Lines changed: 26 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -852,28 +852,36 @@ preserve the name and the modifier `required`, if any. An optional
852852
positional or named parameter remains optional; if it has a default value
853853
`d` in _L_ then it has the default value `d` in _L2_ as well.
854854

855+
If _D_ is an extension type declaration, then it's an error if
856+
_L_ does not have a single formal parameter (positional or named),
857+
or if that parameter does not have the form `T p` or `final T p`
858+
where `T` is a type and `p` is an identifier.
859+
_It's an error if the parameter declaration uses `var` or has a
860+
`covariant` modifier._
861+
The parameter is replaced by `this.p` in _L2_.
862+
The extension type has a representation type of `T` and
863+
a representation value getter with signature `T get p;`.
864+
865+
Otherwise _D_ is a class, mixin class or enum declaration:
855866
- An initializing formal parameter *(e.g., `T this.x`)* is copied from _L_
856867
to _L2_, with no changes.
857868
- A super parameter is copied from _L_ to _L2_ any, with no changes.
858869
- A formal parameter which is not covered by the previous two cases and
859-
which does not have the modifier `var` or the modifier `final` is copied
860-
unchanged from _L_ to _L2_ *(this is a plain, non-declaring parameter)*.
861-
- Otherwise, it is a declaring parameter. A formal parameter (named or
862-
positional) of the form `var T p` or `final T p` where `T` is a type and
863-
`p` is an identifier is replaced in _L2_ by `this.p`, along with its
864-
default value, if any. The same is done in the case where the formal
865-
parameter has the form `var p` or `final p`, and `T` is the declared type
866-
of `p` which was obtained by inference. If the parameter has the modifier
867-
`var` and _D_ is an extension type declaration then a compile-time error
868-
occurs. Otherwise, if _D_ is not an extension type declaration, a
869-
semantic instance variable declaration corresponding to the syntax `T p;`
870-
or `final T p;` is added to _D2_. It includes the modifier `final` if and
871-
only if the parameter in _L_ has the modifier `final` and _D_ is not an
872-
`extension type` decaration. Otherwise, if _D_ is an `extension type`
873-
declaration then the name of `p` specifies the name of the representation
874-
variable. In all cases, if `p` has the modifier `covariant` then this
875-
modifier is removed from the parameter in _L2_, and it is added to the
876-
instance variable declaration named `p`.
870+
which does not have the modifier `var` or the modifier `final`,
871+
is copied unchanged from _L_ to _L2_
872+
*(this is a plain, non-declaring parameter)*.
873+
- Otherwise, it is a declaring parameter, a formal parameter (named or positional)
874+
of the form `final T p`, `final p`, `var T p` or `var p`, the last two optionally
875+
prefixed by `covariant`, where `T` is a type and `p` is an identifier.
876+
It is replaced in _L2_ by `this.p`, along with its default value, if any.
877+
Let `T` be the type of the formal parameter, whether declared explicitly
878+
or inferred.
879+
A semantic instance variable declaration corresponding to the syntax `T p;`,
880+
`covariant T p;` or `final T p;` is added to _D2_.
881+
It includes the modifier `final` if and only if the parameter in _L_ has
882+
the modifier `final`. It includes the `covariant` modifier if the
883+
parameter in _L_ has the modifier `covariant`, or if the instance variable
884+
overrides an instance setter with a covariant parameter, and otherwise not.
877885

878886
If there is a primary constructor body part that contains an initializer
879887
list then _k2_ has an initializer list with the same elements in the same

0 commit comments

Comments
 (0)