Skip to content

Commit

Permalink
Update with expression in records-wip
Browse files Browse the repository at this point in the history
  • Loading branch information
agocke authored Apr 10, 2020
1 parent 52624f5 commit 88202ac
Showing 1 changed file with 5 additions and 24 deletions.
29 changes: 5 additions & 24 deletions proposals/records-wip.md
Original file line number Diff line number Diff line change
Expand Up @@ -89,32 +89,13 @@ A `with` expression allows for "non-destructive mutation", designed to
produce a copy of the receiver expression with modifications to properties
listed in the `anonymous_object_initializer`.

A valid `with` expression has a receiver with a non-void type. The receiver type must contain an accessible instance method called `With` with
the appropriate parameters and return type. It is an error if there are multiple non-override `With` methods. If there are multiple `With` overrides,
there must be a non-override `With` method, which is the target method. Otherwise, there must be exactly one `With` method.
A valid `with` expression has a receiver with a non-void type. The receiver type must contain an accessible parameterless instance method called `Clone` whose return type must be the type of the receiver express type, or a base type thereof.

On the right hand side of the `with` expression is an `anonymous_object_initializer` with a
sequence of assignments with a field or property of the receiver on the left-hand side of the
sequence of assignments with a compiler-generated record property of the receiver on the left-hand side of the
assignment, and an arbitrary expression on the right-hand side which is implicitly convertible to the type
of the left-hand side.

Given a target `With` method, the return type must be the type of the receiver expression type, or a base type thereof. For each parameter of
the `With` method, there must be an accessible corresponding instance field or readable property on the
receiver type with the same name and the same type. Each property or field in the right-hand side of the With
expression must also correspond to a parameter of the same name in the `With` method.

Given a valid `With` method, the evaluation of a `with` expression is equivalent to calling the `With` method with the expressions in the
`anonymous_object_initializer` substituted for the parameter of the same
name as the property on the left hand side. If there is no matching property
for a given parameter in the `anonymous_object_initializer`, the argument
is the evaluation of the field or property of the same name on the receiver.

The order of evaluation of side effects is as follows, with each expression
evaluated exactly once:

1. Receiver expression

2. Expressions in the `anonymous_object_initializer`, in lexical order

3. The evaluation of any properties matching the `With` method parameters,
in order of definition of the `With` method parameters.
The evaluation of a `with` expression is equivalent to calling the `Clone` method exactly once,
and then setting the backing field of each record property in the argument list to its corresponding
expression, in lexical order, using the result of the `Clone` method as the receiver.

0 comments on commit 88202ac

Please sign in to comment.