Skip to content

Commit ffd3367

Browse files
authored
Support static abstract members in interfaces
1 parent 46e714b commit ffd3367

1 file changed

Lines changed: 24 additions & 16 deletions

File tree

standard/interfaces.md

Lines changed: 24 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ If a generic interface is declared in multiple parts ([§15.2.3](classes.md#1523
9494
9595
#### 19.2.3.2 Variance safety
9696
97-
The occurrence of variance annotations in the type parameter list of a type restricts the places where types can occur within the type declaration. However, these restrictions do not apply to occurrences of types within a declaration of a static member.
97+
The occurrence of variance annotations in the type parameter list of a type restricts the places where types can occur within the type declaration. However, these restrictions do not apply to occurrences of types within a declaration of a non-virtual, non-abstract static member.
9898
9999
A type `T` is ***output-unsafe*** if one of the following holds:
100100
@@ -233,15 +233,15 @@ interface_member_declaration
233233
;
234234
```
235235

236-
This clause augments the description of members in classes ([§15.3](classes.md#153-class-members)) with the differences and restrictions for interfaces:
236+
This subclause augments the description of members in classes ([§15.3](classes.md#153-class-members)) with the differences and restrictions for interfaces:
237237

238238
- A *finalizer_declaration* is not allowed.
239239
- Instance constructors, *constructor_declaration*s, are not allowed.
240240
- All interface members implicitly have public access; however, an explicit access modifier ([§7.5.2](basic-concepts.md#752-declared-accessibility)) is permitted except on static constructors ([§15.12](classes.md#1512-static-constructors)).
241-
- The `abstract` modifier is implied for interface function members ([§12.6](expressions.md#126-function-members)) without bodies; that modifier may be given explicitly.
242-
- An interface instance function member whose declaration includes a body is an implicitly `virtual` member unless the `sealed` or `private` modifier is used. The `virtual` modifier may be given explicitly.
241+
- The `abstract` modifier is implied for interface instance function members ([§12.6](expressions.md#126-function-members)) without bodies; that modifier may be given explicitly. For interface static function members without bodies the `abstract` modifier shall be present.
242+
- An interface instance function member whose declaration includes a body is an implicitly `virtual` member unless the `sealed` or `private` modifier is used. The `virtual` modifier may be given explicitly. An interface static member whose declaration includes a body may have a `virtual` modifier.
243243
- A `private` or `sealed` function member of an interface shall have a body.
244-
- A `private` function member shall not have the modifier `sealed`.
244+
- A `private` instance function member shall not have the modifier `sealed`.
245245
- A derived interface may override an abstract or virtual member declared in a base interface.
246246
- An explicitly implemented function member shall not have the modifier `sealed`.
247247

@@ -429,7 +429,7 @@ A virtual method with implementation declared in an interface may be overridden
429429
430430
### 19.4.4 Interface properties
431431
432-
This clause augments the description of properties in classes [§15.7](classes.md#157-properties) for properties declared in interfaces.
432+
This subclause augments the description of properties in classes [§15.7](classes.md#157-properties) for properties declared in interfaces.
433433
434434
Interface properties are declared using *property_declaration*s ([§15.7.1](classes.md#1571-general)) with the following additional rules:
435435
@@ -440,25 +440,27 @@ Interface properties are declared using *property_declaration*s ([§15.7.1](clas
440440
> *Note*: As an interface cannot contain instance fields, an interface property cannot be an instance auto-property, as that would require the declaration of implicit hidden instance fields. *end note*
441441
442442
- 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 or init accessor.
443-
- An interface method declaration that has a block body or expression body as a *method_body* is `virtual`; the `virtual` modifier is not required, but is allowed.
444-
- An instance *property_declaration* that has no implementation is `abstract`; the `abstract` modifier is not required, but is allowed. It is *never* considered to be an automatically implemented property ([§15.7.4](classes.md#1574-automatically-implemented-properties)).
443+
- An interface instance method declaration that has a block body or expression body as a *method_body* is `virtual`; the `virtual` modifier is not required, but is allowed. For a static method the `virtual` modifier is permitted.
444+
- An instance *property_declaration* that has no implementation is `abstract`; the `abstract` modifier is not required, but is allowed. It is *never* considered to be an automatically implemented property ([§15.7.4](classes.md#1574-automatically-implemented-properties)). However, the `abstract` modifier shall be present if a static property is to be abstract.
445+
- A *property_declaration* may contain the `sealed` modifier.
445446
446447
### 19.4.5 Interface events
447448
448-
This clause augments the description of events in classes15.8](classes.md#158-events) for events declared in interfaces.
449+
This subclause augments the description of events in classes [§15.8](classes.md#158-events) for events declared in interfaces.
449450
450451
Interface events are declared using *event_declaration*s ([§15.8.1](classes.md#1581-general)), with the following additional rules:
451452
452453
- *event_modifier* shall not include `override`.
453454
- A derived interface may implement an abstract interface event declared in a base interface ([§15.8.5](classes.md#1585-virtual-sealed-override-and-abstract-accessors)).
454455
- It is a compile-time error for *variable_declarators* in an instance *event_declaration* to contain any *variable_initializer*s.
455-
- An instance event with the `virtual` or `sealed` modifiers must declare accessors. It is *never* considered to be an automatically implemented field-like event ([§15.8.2](classes.md#1582-field-like-events)).
456-
- An instance event with the `abstract` modifier must not declare accessors.
456+
- An instance event with the `virtual` or `sealed` modifiers shall declare accessors. It is *never* considered to be an automatically implemented field-like event ([§15.8.2](classes.md#1582-field-like-events)).
457+
- An instance event with the `abstract` modifier shall not declare accessors.
458+
- A static event may have `abstract`, `virtual`, and `sealed` modifiers.
457459
- The type of an interface event shall be input-safe.
458460
459461
### 19.4.6 Interface indexers
460462
461-
This clause augments the description of indexers in classes [§15.9](classes.md#159-indexers) for indexers declared in interfaces.
463+
This sub clause augments the description of indexers in classes [§15.9](classes.md#159-indexers) for indexers declared in interfaces.
462464
463465
Interface indexers are declared using *indexer_declaration*s ([§15.9](classes.md#159-indexers)), with the following additional rules:
464466
@@ -474,15 +476,19 @@ Interface indexers are declared using *indexer_declaration*s ([§15.9](classes.m
474476
475477
### 19.4.7 Interface operators
476478
477-
This clause augments the description of *operator_declaration* members in classes [§15.10](classes.md#1510-operators) for operators declared in interfaces.
479+
This subclause augments the description of *operator_declaration* members in classes [§15.10](classes.md#1510-operators) for operators declared in interfaces.
478480
479481
For an *operator_declaration* in an interface the *operator_body* shall only be a block body ([§15.6.1](classes.md#1561-general)) or an expression body ([§15.6.1](classes.md#1561-general)).
480482
481-
It is a compile-time error for an interface to declare a conversion, equality, or inequality operator.
483+
A static *operator_declaration* may have `abstract`, `virtual`, and `sealed` modifiers.
484+
485+
In the context of a class or struct, at least one of the *fixed_parameter*s in a *unary_operator_declarator* and *binary_operator_declarator* is required to have type `T` or `T?`, where `T` is the instance type of the enclosing type. This requirement is relaxed in the context of an interface in that a restricted operand is allowed to be of a type parameter that counts as “the instance type of the enclosing type.” In order for a type parameter `T` to count as that it shall meet the following requirements:
486+
- `T` is a direct type parameter on the interface in which the operator declaration occurs, and
487+
- `T` is directly constrained by the instance type; i.e., the surrounding interface with its own type parameters used as type arguments.
482488
483489
### 19.4.8 Interface static constructors
484490
485-
This clause augments the description of static constructors in classes [§15.12](classes.md#1512-static-constructors) for static constructors declared in interfaces.
491+
This subclause augments the description of static constructors in classes [§15.12](classes.md#1512-static-constructors) for static constructors declared in interfaces.
486492
487493
The static constructor for a closed ([§8.4.3](types.md#843-open-and-closed-types)) interface executes at most once in a given application domain. The execution of a static constructor is triggered by the first of the following actions to occur within an application domain:
488494
@@ -498,7 +504,7 @@ To initialize a new closed interface type, first a new set of static fields for
498504
499505
### 19.4.9 Interface nested types
500506
501-
This clause augments the description of nested types in classes [§15.3.9](classes.md#1539-nested-types) for nested types declared in interfaces.
507+
This subclause augments the description of nested types in classes [§15.3.9](classes.md#1539-nested-types) for nested types declared in interfaces.
502508
503509
It is an error to declare a class type, struct type, or enum type within the scope of a type parameter that was declared with a *variance_annotation* ([§19.2.3.1](interfaces.md#19231-general)).
504510
@@ -949,6 +955,8 @@ The qualified interface member name of an explicit interface member implementati
949955
>
950956
> *end example*
951957
958+
An explicit interface member implementation that implements a static member shall itself be static.
959+
952960
### 19.6.3 Uniqueness of implemented interfaces
953961
954962
The interfaces implemented by a generic type declaration shall remain unique for all possible constructed types. Without this rule, it would be impossible to determine the correct method to call for certain constructed types.

0 commit comments

Comments
 (0)