From 88202acd40ca04b6e513ea1e5993625ee26fac3f Mon Sep 17 00:00:00 2001 From: Andy Gocke Date: Fri, 10 Apr 2020 12:34:23 -0700 Subject: [PATCH] Update with expression in records-wip --- proposals/records-wip.md | 29 +++++------------------------ 1 file changed, 5 insertions(+), 24 deletions(-) diff --git a/proposals/records-wip.md b/proposals/records-wip.md index fdcb27f328..daccf36e7d 100644 --- a/proposals/records-wip.md +++ b/proposals/records-wip.md @@ -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.