You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Changes for ref-valued properties, indexers and methods
(This was originally in #837.)
The grammar has been extended to be as prescriptive as reasonably possible as befits a language specification[1], this means that former statements such as it being illegal to have a set accessor for a ref-valued property are now covered by the grammar. However the usual verbose description of the grammar remains!
The term ref-valued rather than ref-returning is used, a term closer to the language of fields. To distingush the two kinds of properties, which do follow different rules, the corresponding and somewhat ugly term non-ref-valued is used (non-ref-returning would be just as ugly).
[1] The grammar used by a compiler may be less restrictive to support more descriptive error messages, that is of course an implementation issue!
Fixes#825.
*unsafe_modifier* is defined in [§23.2](unsafe-code.md#232-unsafe-contexts).
30
39
31
40
It is a compile-time error for the same modifier to appear multiple times in a delegate declaration.
32
41
33
-
A delegate declaration shall not supply any *type_parameter_constraints_clause*s unless it also supplies a *variant_type_parameter_list*.
34
-
35
42
A delegate declaration that supplies a *variant_type_parameter_list* is a generic delegate declaration. Additionally, any delegate nested inside a generic class declaration or a generic struct declaration is itself a generic delegate declaration, since type arguments for the containing type shall be supplied to create a constructed type ([§8.4](types.md#84-constructed-types)).
36
43
37
44
The `new` modifier is only permitted on delegates declared within another type, in which case it specifies that such a delegate hides an inherited member by the same name, as described in [§15.3.5](classes.md#1535-the-new-modifier).
@@ -40,11 +47,13 @@ The `public`, `protected`, `internal`, and `private` modifiers control the acces
40
47
41
48
The delegate’s type name is *identifier*.
42
49
43
-
As with methods ([§15.6.1](classes.md#1561-general)), if `ref` is present, the delegate returns-by-ref; otherwise, if *return_type* is `void`, the delegate returns-no-value; otherwise, the delegate returns-by-value. It is a compile-time error to have both `ref` and a *return_type* of `void`.
50
+
As with methods ([§15.6.1](classes.md#1561-general)), if `ref` is present, the delegate returns-by-ref; otherwise, if *return_type* is `void`, the delegate returns-no-value; otherwise, the delegate returns-by-value.
44
51
45
52
The optional *formal_parameter_list* specifies the parameters of the delegate.
46
53
47
-
*return_type* indicates the return type of the delegate. The optional `ref` indicates that a *variable reference* ([§9.5](variables.md#95-variable-references)) is returned, with the optional `readonly` indicating that that variable is read-only.
54
+
The *return_type* of a returns-by-value or returns-no-value delegate declaration specifies the type of the result, if any, returned by the delegate.
55
+
56
+
The *ref_return_type* of a returns-by-ref delegate declaration specifies the type of the variable referenced by the *variable_reference* ([§9.5](variables.md#95-variable-references)) returned by the delegate.
48
57
49
58
The optional *variant_type_parameter_list* ([§18.2.3](interfaces.md#1823-variant-type-parameter-lists)) specifies the type parameters to the delegate itself.
50
59
@@ -76,7 +85,7 @@ The only way to declare a delegate type is via a *delegate_declaration*. Every d
76
85
77
86
## 20.3 Delegate members
78
87
79
-
Everydelegatetypeinheritsmembersfromthe `Delegate` classasdescribedin [§15.3.4](classes.md#1534-inheritance). Inaddition, everydelegate type must provide a non-generic `Invoke` method whose parameter list matches the *formal_parameter_list* in the delegate declaration, andwhosereturntypematchesthe*return_type*inthedelegate declaration. The `Invoke` method shall be at least as accessible as the containing delegate type. Calling the `Invoke` method on a delegate type is semantically equivalent to using the delegate invocation syntax ([§20.6](delegates.md#206-delegate-invocation)) .
88
+
Everydelegatetypeinheritsmembersfromthe `Delegate` classasdescribedin [§15.3.4](classes.md#1534-inheritance). Inaddition, everydelegate type must provide a non-generic `Invoke` method whose parameter list matches the *formal_parameter_list* in the delegate declaration, whosereturntypematchesthe*return_type*or*ref_return_type*inthedelegate declaration, andforreturns-by-refdelegateswhose*ref_kind*matchesthatinthedelegate declaration. The `Invoke` method shall be at least as accessible as the containing delegate type. Calling the `Invoke` method on a delegate type is semantically equivalent to using the delegate invocation syntax ([§20.6](delegates.md#206-delegate-invocation)) .
Copy file name to clipboardExpand all lines: standard/expressions.md
+2-2
Original file line number
Diff line number
Diff line change
@@ -1539,7 +1539,7 @@ simple_name
1539
1539
A *simple_name* is either of the form `I` or of the form `I<A₁, ..., Aₑ>`, where `I` is a single identifier and `I<A₁, ..., Aₑ>` is an optional *type_argument_list*. When no *type_argument_list* is specified, consider `e` to be zero. The *simple_name* is evaluated and classified as follows:
1540
1540
1541
1541
- If `e` is zero and the *simple_name* appears within a local variable declaration space ([§7.3](basic-concepts.md#73-declarations)) that directly contains a local variable, parameter 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.
1542
-
- If `e` is zero and the *simple_name* appears within a generic method declaration but outside the *attributes* of its *method_header,* and if that declaration includes a type parameter with name `I`, then the *simple_name* refers to that type parameter.
1542
+
- 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.
1543
1543
- 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):
1544
1544
- 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.
1545
1545
- Otherwise, if a member lookup ([§12.5](expressions.md#125-member-lookup)) of `I` in `T` with `e` type arguments produces a match:
@@ -4749,7 +4749,7 @@ The first operand of the `?:` operator shall be an expression that can be impli
4749
4749
If `ref` is present:
4750
4750
4751
4751
- An identity conversion must exist between the types of the two *variable_reference*s, and type of the result can be either type. If either type is `dynamic`, type inference prefers `dynamic` ([§8.7](types.md#87-the-dynamic-type)). If either type is a tuple type ([§8.3.11](types.md#8311-tuple-types)), type inference includes the element names when the element names in the same ordinal position match in both tuples.
4752
-
- The result is a variable reference, which is writeable if both *variable_reference*s are writeable.
4752
+
- The result is a variable reference, which is writeable if both *variable_reference*s are writeable.
4753
4753
4754
4754
> *Note*: When `ref` is present, the *conditional_expression* returns a variable reference, which can be assigned to a reference variable using the `= ref` operator or passed as a reference/input/output parameter. *end note*
The *attributes*, *return_type*, *identifier*, and *formal_parameter_list* of an interface method declaration have the same meaning as those of a method declaration in a class ([§15.6](classes.md#156-methods)). An interface method declaration is not permitted to specify a method body, and the declaration therefore always ends with a semicolon. An *interface_method_declaration* shall not have *type_parameter_constraints_clause*s unless it also has a *type_parameter_list*.
267
+
The *attributes*, *return_type*, *ref_return_type*, *identifier*, and *formal_parameter_list* of an interface method declaration have the same meaning as those of a method declaration in a class ([§15.6](classes.md#156-methods)). An interface method declaration is not permitted to specify a method body, and the declaration therefore always ends with a semicolon.
263
268
264
269
All formal parameter types of an interface method shall be input-safe ([§18.2.3.2](interfaces.md#18232-variance-safety)), and the return type shall be either `void` or output-safe. In addition, any output or reference formal parameter types shall also be output-safe.
265
270
266
-
> *Note*: Output parameters are required to be input-safe due to common implementation restrictions. *end note*
271
+
> *Note*: Output parameters are required to be input-safe due to common implementation restrictions. *end note*
267
272
268
273
Furthermore, each class type constraint, interface type constraint and type parameter constraint on any type parameters of the method shall be input-safe.
269
274
@@ -313,21 +318,24 @@ Interface properties are declared using *interface_property_declaration*s:
The *attributes*, *type*, and *identifier* of an interface property declaration have the same meaning as those of a property declaration in a class ([§15.7](classes.md#157-properties)).
329
337
330
-
The accessors of an interface property declaration correspond to the accessors of a class property declaration ([§15.7.3](classes.md#1573-accessors)), except that the accessor body shall always be a semicolon. Thus, the accessors simply indicate whether the property is read-write, read-only, or write-only.
338
+
The accessors of an interface property declaration correspond to the accessors of a class property declaration ([§15.7.3](classes.md#1573-accessors)), except that the *accessor_body* shall always be a semicolon. Thus, the accessors simply indicate whether the property is read-write, read-only, or write-only.
331
339
332
340
The type of an interface property shall be output-safe if there is a get accessor, and shall be input-safe if there is a set accessor.
333
341
@@ -350,15 +358,17 @@ The type of an interface event shall be input-safe.
350
358
Interface indexers are declared using *interface_indexer_declaration*s:
351
359
352
360
```ANTLR
353
-
interface_indexer_declaration:
354
-
attributes? 'new'? type 'this' '[' formal_parameter_list ']'
355
-
'{' interface_accessors '}'
361
+
interface_indexer_declaration
362
+
: attributes? 'new'? type 'this' '[' formal_parameter_list ']'
363
+
'{' interface_accessors '}'
364
+
| attributes? 'new'? ref_kind type 'this' '[' formal_parameter_list ']'
365
+
'{' ref_interface_accessor '}'
356
366
;
357
367
```
358
368
359
369
The *attributes*, *type*, and *formal_parameter_list* of an interface indexer declaration have the same meaning as those of an indexer declaration in a class ([§15.9](classes.md#159-indexers)).
360
370
361
-
The accessors of an interface indexer declaration correspond to the accessors of a class indexer declaration ([§15.9](classes.md#159-indexers)), except that the accessor body shall always be a semicolon. Thus, the accessors simply indicate whether the indexer is read-write, read-only, or write-only.
371
+
The accessors of an interface indexer declaration correspond to the accessors of a class indexer declaration ([§15.9](classes.md#159-indexers)), except that the *accessor_body* shall always be a semicolon. Thus, the accessors simply indicate whether the indexer is read-write, read-only, or write-only.
362
372
363
373
All the formal parameter types of an interface indexer shall be input-safe ([§18.2.3.2](interfaces.md#18232-variance-safety)). In addition, any output or reference formal parameter types shall also be output-safe.
Copy file name to clipboardExpand all lines: standard/lexical-structure.md
+1-1
Original file line number
Diff line number
Diff line change
@@ -1297,7 +1297,7 @@ Conditional compilation directives shall be written in groups consisting of, in
1297
1297
1298
1298
At most one of the contained conditional sections is selected for normal lexical processing:
1299
1299
1300
-
- The *PP_Expression*s of the `#if` and `#elif` directives are evaluated in order until one yields `true`. If an expression yields `true`, the conditional section following the corresponding directive is selected.
1300
+
- The *PP_Expression*s of the `#if` and `#elif` directives are evaluated in order until one yields `true`. If an expression yields `true`, the conditional section following the corresponding directive is selected.
1301
1301
- If all *PP_Expression*s yield `false`, and if a `#else` directive is present, the conditional section following the `#else` directive is selected.
0 commit comments