Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions standard/basic-concepts.md
Original file line number Diff line number Diff line change
Expand Up @@ -689,16 +689,17 @@ The ***scope*** of a name is the region of program text within which it is possi
- The scope of a type parameter declared by a *type_parameter_list* on a *struct_declaration* ([§16.2](structs.md#162-struct-declarations)) is the *delimited_parameter_list* (if any), *struct_interfaces*, *type_parameter_constraints_clause*s, and *struct_body* (or *record_struct_body*) of that *struct_declaration*.
- The scope of a type parameter declared by a *type_parameter_list* on an *interface_declaration* ([§19.2](interfaces.md#192-interface-declarations)) is the *interface_base*, *type_parameter_constraints_clause*s, and *interface_body* of that *interface_declaration*.
- The scope of a type parameter declared by a *type_parameter_list* on a *delegate_declaration* ([§21.2](delegates.md#212-delegate-declarations)) is the *return_type*, *parameter_list*, and *type_parameter_constraints_clause*s of that *delegate_declaration*.
- The scope of a type parameter declared by a *type_parameter_list* on a *method_declaration* ([§15.6.1](classes.md#1561-general)) is the *method_declaration*.
- The scope of a type parameter declared by a *type_parameter_list* on a *method_declaration* ([§15.6.1](classes.md#1561-general)) is the *method_declaration* and `nameof` expressions in an attribute on the *method_declaration* or its parameters.
- The scope of a member declared by a *class_member_declaration* ([§15.3.1](classes.md#1531-general)) is the *class_body* (or *record_class_body*) in which the declaration occurs. In addition, the scope of a class member extends to the *class_body* (or *record_class_body*) of those derived classes that are included in the accessibility domain ([§7.4.3](basic-concepts.md#743-accessibility-domains)) of the member.
- The scope of a member declared by a *struct_member_declaration* ([§16.3](structs.md#163-struct-members)) is the *struct_body* (or *record_struct_body*) in which the declaration occurs.
- The scope of a member declared by an *enum_member_declaration* ([§20.4](enums.md#204-enum-members)) is the *enum_body* in which the declaration occurs.
- The scope of a parameter declared in a *method_declaration* ([§15.6](classes.md#156-methods)) is the *method_body* or *ref_method_body* of that *method_declaration*.
- The scope of a parameter declared in a *method_declaration* ([§15.6](classes.md#156-methods)) is the *method_body* or *ref_method_body* of that *method_declaration* and `nameof` expressions in an attribute on the method declaration or its parameters.
- The scope of a parameter declared in a *delegate_declaration* is specified in [§21.2](delegates.md#212-delegate-declarations).
- The scope of a parameter declared in an *indexer_declaration* ([§15.9](classes.md#159-indexers)) is the *indexer_body* of that *indexer_declaration*.
- The scope of a parameter declared in an *operator_declaration* ([§15.10](classes.md#1510-operators)) is the *operator_body* of that *operator_declaration*.
- The scope of a parameter declared in a *constructor_declaration* ([§15.11](classes.md#1511-instance-constructors)) is the *constructor_initializer* and *block* of that *constructor_declaration*.
- The scope of a non-discard parameter ([§12.22.2](expressions.md#12222-anonymous-function-signatures)) declared in a *lambda_expression* ([§12.22](expressions.md#1222-anonymous-function-expressions)) is the *lambda_expression_body* of that *lambda_expression*.
- The scope of a non-discard parameter ([§12.22.2](expressions.md#12222-anonymous-function-signatures)) declared in an *anonymous_method_expression* ([§12.22](expressions.md#1222-anonymous-function-expressions)) is the *block* of that *anonymous_method_expression*.
- The scope of a non-discard parameter ([§12.22.2](expressions.md#12222-anonymous-function-signatures)) declared in a *lambda_expression* ([§12.22](expressions.md#1222-anonymous-function-expressions)) is the *lambda_expression_body* of that *lambda_expression* and `nameof` expressions in an attribute on the anonymous function or its parameters.
- The scope of a non-discard parameter ([§12.22.2](expressions.md#12222-anonymous-function-signatures)) declared in an *anonymous_method_expression* ([§12.22](expressions.md#1222-anonymous-function-expressions)) is the *block* of that *anonymous_method_expression* and `nameof` expressions in an attribute on the anonymous function or its parameters.
- The scope of a label declared in a *labeled_statement* ([§13.5](statements.md#135-labeled-statements)) is the *block* in which the declaration occurs.
- The scope of a local variable declared in a *local_variable_declaration* ([§13.6.2](statements.md#1362-local-variable-declarations)) is the *block* in which the declaration occurs.
- The scope of a local variable declared in a *switch_block* of a `switch` statement ([§13.8.3](statements.md#1383-the-switch-statement)) is the *switch_block*.
Expand Down
6 changes: 3 additions & 3 deletions standard/classes.md
Original file line number Diff line number Diff line change
Expand Up @@ -2220,7 +2220,7 @@ The name, the number of type parameters, and the parameter list of a method defi

The name of a method shall differ from the names of all other non-methods declared in the same class. In addition, the signature of a method shall differ from the signatures of all other methods declared in the same class, and two methods declared in the same class shall not have signatures that differ solely by `in`, `out`, and `ref`.

The method’s *type_parameter*s are in scope throughout the *method_declaration*, and can be used to form types throughout that scope in *return_type* or *ref_return_type*, *method_body* or *ref_method_body*, and *type_parameter_constraints_clause*s but not in *attributes*.
The method’s *type_parameter*s are in scope throughout the *method_declaration*, and can be used to form types throughout that scope in *return_type* or *ref_return_type*, *method_body* or *ref_method_body*, and *type_parameter_constraints_clause*s but not in *attributes*, except within a `nameof` expression in *attributes*.

All parameters and type parameters shall have different names.

Expand Down Expand Up @@ -2332,9 +2332,9 @@ A *parameter_array* may occur after an optional parameter, but cannot have a def
>
> *end example*

A method declaration creates a separate declaration space ([§7.2](basic-concepts.md#72-declarations)) for parameters and type parameters. Names are introduced into this declaration space by the type parameter list and the parameter list of the method. The body of the method, if any, is considered to be nested within this declaration space. It is an error for two members of a method declaration space to have the same name.
A method declaration creates a separate declaration space ([§7.2](basic-concepts.md#72-declarations)) for parameters and type parameters. Names are introduced into this declaration space by the type parameter list and the parameter list of the method. These names are also in scope in `nameof` expressions in attributes placed on the method or its parameters. The body of the method, if any, is considered to be nested within this declaration space. It is an error for two members of a method declaration space to have the same name.

A method invocation ([§12.8.10.2](expressions.md#128102-method-invocations)) creates a copy, specific to that invocation, of the parameters and local variables of the method, and the argument list of the invocation assigns values or variable references to the newly created parameters. Within the *block* of a method, parameters can be referenced by their identifiers in *simple_name* expressions ([§12.8.4](expressions.md#1284-simple-names)).
A method invocation ([§12.8.10.2](expressions.md#128102-method-invocations)) creates a copy, specific to that invocation, of the parameters and local variables of the method, and the argument list of the invocation assigns values or variable references to the newly created parameters. Within the *block* of a method, parameters can be referenced by their identifiers in *simple_name* expressions ([§12.8.4](expressions.md#1284-simple-names)). Within a `nameof` expression in attributes placed on the method or its parameters, formal parameters can be referenced by their identifiers in *simple_name* expressions.

The following kinds of parameters exist:

Expand Down
2 changes: 1 addition & 1 deletion standard/delegates.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ The delegate’s type name is *identifier*.

As with methods ([§15.6.1](classes.md#1561-general)), if `ref` is present, the delegate return-by-ref; otherwise, if *return_type* is `void`, the delegate return-no-value; otherwise, the delegate return-by-value.

The optional *parameter_list* specifies the parameters of the delegate.
The optional *parameter_list* specifies the parameters of the delegate. The scope of the parameters of the delegate is `nameof` expressions in attributes placed on the declaration, its type parameters, or its parameters.

The *return_type* of a return-by-value or return-no-value delegate declaration specifies the type of the result, if any, returned by the delegate.

Expand Down
4 changes: 3 additions & 1 deletion standard/expressions.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# 12 Expressions

Check warning on line 2 in standard/expressions.md

View workflow job for this annotation

GitHub Actions / word-converter

Markdown to Word Converter - MDC032

Line length 84 > maximum 83; : null_conditional_member_access null_forgiving_operator? '(' argument_list? ')'
## 12.1 General

An expression is a sequence of operators and operands. This clause defines the syntax, order of evaluation of operands and operators, and meaning of expressions.
Expand All @@ -15,7 +15,7 @@

### 12.2.1 General

The result of an expression is classified as one of the following:

Check warning on line 18 in standard/expressions.md

View workflow job for this annotation

GitHub Actions / word-converter

Markdown to Word Converter - MDC032

Line length 99 > maximum 83; Console.WriteLine(formattable.ToString(System.Globalization.CultureInfo.InvariantCulture));

- A value. Every value has an associated type.
- A variable. Unless otherwise specified, a variable is explicitly typed and has an associated type, namely the declared type of the variable. An implicitly typed variable has no associated type.
Expand Down Expand Up @@ -1709,6 +1709,8 @@

- If `e` is zero and the *simple_name* appears within a local variable declaration space ([§7.2](basic-concepts.md#72-declarations)) that directly contains a local variable, parameter (with the exception of discard parameters ([§12.22.2](expressions.md#12222-anonymous-function-signatures))), or constant with name `I`, then the *simple_name* refers to that local variable, parameter or constant and is classified as a variable or value.
- If `e` is zero and the *simple_name* appears within a generic method declaration but outside the *attributes* of its *method_declaration*, and if that declaration includes a type parameter with name `I`, then the *simple_name* refers to that type parameter.
- If `e` is zero and the *simple_name* appears within a `nameof` expression in an attribute on the method declaration or its parameters, and if that declaration includes a parameter or type parameter with name `I`, then the *simple_name* refers to that parameter or type parameter.
- If `e` is zero and the *simple_name* appears within a `nameof` expression in an attribute on a delegate declaration, its type parameters, or its parameters ([§21.2](delegates.md#212-delegate-declarations)), and if that declaration includes a parameter with name `I`, then the *simple_name* refers to that parameter and is classified as a variable or value.
- Otherwise, for each instance type `T` ([§15.3.2](classes.md#1532-the-instance-type)), starting with the instance type of the immediately enclosing type declaration and continuing with the instance type of each enclosing class or struct declaration (if any):
- If the declaration of `T` includes a primary constructor parameter `I` and the reference occurs within the `argument_list` of `T`’s `class_base` or within an initializer of a field, property or event of `T`, the result is the primary constructor parameter `I`.
- Otherwise, if `e` is zero and the declaration of `T` includes a type parameter with name `I`, then the *simple_name* refers to that type parameter.
Expand Down Expand Up @@ -5713,7 +5715,7 @@

In an anonymous function parameter list, if two or more of the *identifier*s occurring directly in its *explicit_anonymous_function_parameter*s or *implicit_anonymous_function_parameter*s are *discard_token*s, each corresponding parameter is a ***discard parameter*** ([§9.2.9.2](variables.md#9292-discards)). All other parameters are non-discard parameters, whose names are specified by their *identifier*s.

The *anonymous_function_signature* of an anonymous function defines the names of the non-discard parameters and optionally the types and *attributes* of all the parameters for the anonymous function. The scope of the non-discard parameters of the anonymous function is the *anonymous_function_body* ([§7.6](basic-concepts.md#76-scopes)). Together with the parameter list (if given) the anonymous-method-body constitutes a declaration space ([§7.2](basic-concepts.md#72-declarations)). It is thus a compile-time error for the name of a non-discard parameter of the anonymous function to match the name of a local variable, local constant or parameter whose scope includes the *anonymous_method_expression* or *lambda_expression*.
The *anonymous_function_signature* of an anonymous function defines the names of the non-discard parameters and optionally the types and *attributes* of all the parameters for the anonymous function. The scope of the non-discard parameters of the anonymous function is the *anonymous_function_body* ([§7.6](basic-concepts.md#76-scopes)) and `nameof` expressions in attributes placed on the anonymous function or its parameters. Together with the parameter list (if given) the anonymous-method-body constitutes a declaration space ([§7.2](basic-concepts.md#72-declarations)). It is thus a compile-time error for the name of a non-discard parameter of the anonymous function to match the name of a local variable, local constant or parameter whose scope includes the *anonymous_method_expression* or *lambda_expression*.

> *Note*: Because discard parameters do not introduce a name into any scope, they do not conflict with other parameters, local variables, local constants, or other discard parameters. *end note*
<!-- markdownlint-disable MD028 -->
Expand Down
2 changes: 1 addition & 1 deletion standard/types.md
Original file line number Diff line number Diff line change
Expand Up @@ -794,7 +794,7 @@ Since a type parameter can be instantiated with many different type arguments, t
> - The available conversions for a type parameter depend on the constraints, if any, applied to the type parameter. They are detailed in [§10.2.12](conversions.md#10212-implicit-conversions-involving-type-parameters) and [§10.3.8](conversions.md#1038-explicit-conversions-involving-type-parameters).
> - The literal `null` cannot be converted to a type given by a type parameter, except if the type parameter is known to be a reference type ([§10.2.12](conversions.md#10212-implicit-conversions-involving-type-parameters)). However, a default expression ([§12.8.21](expressions.md#12821-default-value-expressions)) can be used instead. In addition, a value with a type given by a type parameter *can* be compared with null using `==` and `!=` ([§12.15.7](expressions.md#12157-reference-type-equality-operators)) unless the type parameter has the value type constraint.
> - A `new` expression ([§12.8.17.2](expressions.md#128172-object-creation-expressions)) can only be used with a type parameter if the type parameter is constrained by a *constructor_constraint* or the value type constraint ([§15.2.5](classes.md#1525-type-parameter-constraints)).
> - A type parameter cannot be used anywhere within an attribute ([§23.2.1](attributes.md#2321-general)).
> - A type parameter cannot be used within an attribute ([§23.2.1](attributes.md#2321-general)), except within a `nameof` expression in which that type parameter is in scope ([§7.6.1](basic-concepts.md#761-general)).
> - A type parameter cannot be used in a member access ([§12.8.7](expressions.md#1287-member-access)) or type name ([§7.7](basic-concepts.md#77-namespace-and-type-names)) to identify a static member or a nested type.
> - A type parameter can only be used as an *unmanaged_type* ([§8.8](types.md#88-unmanaged-types)) if the type parameter is constrained by the unmanaged constraint ([§15.2.5](classes.md#1525-type-parameter-constraints)).
> - Except when a type parameter is explicitly constrained to value types, the nullable type annotation (`?`) can only be applied to an occurrence of a type parameter when the nullable annotations flag is enabled ([§6.5.9](lexical-structure.md#659-nullable-directive), [§15.2.5](classes.md#1525-type-parameter-constraints)).
Expand Down
Loading