From 00cba6e121e3fbbf9879dde0c15149dca18386e6 Mon Sep 17 00:00:00 2001 From: Bill Wagner Date: Wed, 29 Nov 2023 16:00:17 -0500 Subject: [PATCH] Wordsmithing return by ref (#1006) * wordsmiting on return-by-ref Fixes #805 Clarify that return-by-ref expressions are evaluated the same as return-by-value expressions. The distinction is that for return-by-ref, the result must be a variable reference. * bonus typo fix * Update standard/statements.md Co-authored-by: Jon Skeet --------- Co-authored-by: Jon Skeet --- standard/statements.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/standard/statements.md b/standard/statements.md index f32ea7811..0fc61ea83 100644 --- a/standard/statements.md +++ b/standard/statements.md @@ -313,7 +313,7 @@ Implicitly typed declarations contain the contextual keyword ([§6.4.4](lexical- - If there is no type named `var` in scope and the input matches *implicitly_typed_local_variable_declaration* then it is chosen; - Otherwise if a type named `var` is in scope then *implicitly_typed_local_variable_declaration* is not considered as a possible match. -Within a *local_variable_declaration* each variable is introduced by a ***declarator***, which is one of *implicitly_typed_local_variable_declarator*, *explicitly_typed_local_variable_declarator* or *ref_local_variable_declarator* for impicitly typed, explicitly typed and ref local variables respectively. The declarator defines the name (*identifier*) and initial value, if any, of the introduced variable. +Within a *local_variable_declaration* each variable is introduced by a ***declarator***, which is one of *implicitly_typed_local_variable_declarator*, *explicitly_typed_local_variable_declarator* or *ref_local_variable_declarator* for implicitly typed, explicitly typed and ref local variables respectively. The declarator defines the name (*identifier*) and initial value, if any, of the introduced variable. If there are multiple declarators in a declaration then they are processed, including any initializing expressions, in order left to right ([§9.4.4.5](variables.md#9445-declaration-statements)). @@ -1523,7 +1523,7 @@ It is a compile-time error for a `return` statement to appear in a `finally` blo A `return` statement is executed as follows: -- For a return-by-value, *expression* is evaluated and its value is converted to the effective return type of the containing function by an implicit conversion. The result of the conversion becomes the result value produced by the function. For a return-by-ref, a reference to the *variable_reference* designated by *expression* becomes the result produced by the function. That result is a variable. If the enclosing method’s return-by-ref includes `readonly`, the resulting variable is read-only. +- For a return-by-value, *expression* is evaluated and its value is converted to the effective return type of the containing function by an implicit conversion. The result of the conversion becomes the result value produced by the function. For a return-by-ref, the *expression* is evaluated, and the result shall be classified as a variable. If the enclosing method’s return-by-ref includes `readonly`, the resulting variable is read-only. - If the `return` statement is enclosed by one or more `try` or `catch` blocks with associated `finally` blocks, control is initially transferred to the `finally` block of the innermost `try` statement. When and if control reaches the end point of a `finally` block, control is transferred to the `finally` block of the next enclosing `try` statement. This process is repeated until the `finally` blocks of all enclosing `try` statements have been executed. - If the containing function is not an async function, control is returned to the caller of the containing function along with the result value, if any. - If the containing function is an async function, control is returned to the current caller, and the result value, if any, is recorded in the return task as described in ([§15.15.3](classes.md#15153-evaluation-of-a-task-returning-async-function)).