Skip to content

Commit 736b3b9

Browse files
Nigel-Ecmajskeet
authored andcommitted
[Review]
- #681 has been merged before completion to reduce the conversation & change complexity. This is a review of this PR changes now in draft-v8. Every change will be augmented by a comment in the new PR - Grammar testing, updates post #681 - Update tarball to v2.3.7 - Add sample “Expanded Interfaces”
1 parent 14f2269 commit 736b3b9

12 files changed

Lines changed: 3107 additions & 11 deletions

File tree

211 Bytes
Binary file not shown.

standard/basic-concepts.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -402,7 +402,7 @@ As described in [§7.4](basic-concepts.md#74-members), all members of a base cla
402402
403403
### 7.5.4 Protected access
404404
405-
When a `protected` or `private protected` instance member is accessed outside the program text of the class in which it is declared, and when a `protected internal` instance member is accessed outside the program text of the program in which it is declared, the access shall take place within a class declaration that derives from the class in which it is declared. Furthermore, the access is required to take place *through* an instance of that derived class type or a class type constructed from it. This restriction prevents one derived class from accessing protected members of other derived classes, even when the members are inherited from the same base class. Instance interface members defined with `protected` or `private protected` access cannot be accessed from a `class` or `struct` that implements that interface; these can be accessed only from derived interfaces. However, `class` and `struct` types can define overridden `protected` instance members declared in an interface it implements.
405+
When a `protected` or `private protected` instance member is accessed outside the program text of the class in which it is declared, and when a `protected internal` instance member is accessed outside the program text of the program in which it is declared, the access shall take place within a class declaration that derives from the class in which it is declared. Furthermore, the access is required to take place *through* an instance of that derived class type or a class type constructed from it. This restriction prevents one derived class from accessing protected members of other derived classes, even when the members are inherited from the same base class. Instance interface members defined with `protected` or `private protected` access cannot be accessed from a `class` or `struct` that implements that interface; these can be accessed only from derived interfaces. However, `class` and `struct` types can override `protected` instance members declared in an interface they implement.
406406
407407
Let `B` be a base class that declares a protected instance member `M`, and let `D` be a class that derives from `B`. Within the *class_body* of `D`, access to `M` can take one of the following forms:
408408

standard/classes.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -236,7 +236,7 @@ The direct base class of a class type shall be at least as accessible as the cla
236236
237237
The direct base class of a class type shall not be any of the following types: `System.Array`, `System.Delegate`, `System.Enum`, `System.ValueType` or the `dynamic` type. Furthermore, a generic class declaration shall not use `System.Attribute` as a direct or indirect base class ([§23.2.1](attributes.md#2321-general)).
238238
239-
In determining the meaning of the direct base class specification `A` of a class `B`, the direct base class of `B` is temporarily assumed to be `object`, which ensures that the meaning of a base class specification cannot recursively depend on itself.
239+
In determining the meaning of the direct base class specification `A` of a class `B`, the direct base class of `B` is temporarily assumed to be `object`, which ensures that the meaning of a base class specification cannot recursively depend on itself. Given this definition, the complete set of types upon which a class depends is the transitive closure of the *directly depends on* relationship.
240240
241241
> *Example*: The following
242242
>
@@ -3426,6 +3426,7 @@ For a ref-valued property the *ref_get_accessor_declaration* consists optional a
34263426

34273427
The use of *accessor_modifier*s is governed by the following restrictions:
34283428

3429+
- An *accessor_modifier* shall not be used in an explicit interface member implementation.
34293430
- The *accessor_modifier* `readonly` is permitted only in a *property_declaration* or *indexer_declaration* that is contained directly by a *struct_declaration* ([§16.4.11](structs.md#16411-properties), [§16.4.13](structs.md#16413-indexers)).
34303431
- For a property or indexer that has no `override` modifier, an *accessor_modifier* is permitted only if the property or indexer has both a get and set accessor, and then is permitted only on one of those accessors.
34313432
- For a property or indexer that includes an `override` modifier, an accessor shall match the *accessor_modifier*, if any, of the accessor being overridden.

standard/interfaces.md

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
An interface defines a contract. A class or struct that implements an interface shall adhere to its contract. An interface may inherit from multiple base interfaces, and a class or struct may implement multiple interfaces.
66

7-
Interfaces may contain various kinds of members, as described in [§19.4](interfaces.md#194-interface-members). The interface itself may provide an implementation for some or all of the function members that it declares. Members for which the interface does not provide an implementation are abstract. Their implementations must be supplied by classes or structs that implement the interface, or derived interface that provide an overriding definition.
7+
Interfaces may contain various kinds of members, as described in [§19.4](interfaces.md#194-interface-members). The interface itself may provide an implementation for some or all of the function members that it declares. Members for which the interface does not provide an implementation are abstract. Their implementations must be supplied by classes or structs that implement the interface, and may be supplied by derived interfaces through an explicit implementation ([§19.6.2](interfaces.md#1962-explicit-interface-member-implementations)).
88

99
<!-- This note needs to be updated in C# 13, when ref struct types can implement interfaces. -->
1010
> *Note*: Historically, adding a new function member to an interface impacted all existing consumers of that interface type; it was a breaking change. The addition of interface function member implementations allowed developers to upgrade an interface while still enabling any implementors to override that implementation. Users of the interface can accept the implementation as a non-breaking change; however, if their requirements are different, they can override the provided implementations. *end note*
@@ -233,12 +233,12 @@ interface_member_declaration
233233
;
234234
```
235235

236-
This clause augments the description of members in classes ([§15.3](classes.md#153-class-members)) with restrictions for interfaces. The Interface members are declared using *member_declaration*s with the following additional rules:
236+
This clause 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 without bodies; that modifier may be given explicitly.
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.
242242
- 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.
243243
- A `private` or `sealed` function member of an interface shall have a body.
244244
- A `private` function member shall not have the modifier `sealed`.
@@ -476,7 +476,7 @@ Interface indexers are declared using *indexer_declaration*s ([§15.9](classes.m
476476
477477
This clause augments the description of *operator_declaration* members in classes [§15.10](classes.md#1510-operators) for operators declared in interfaces.
478478
479-
An *operator_declaration* in an interface is the implementation ([§19.1](interfaces.md#191-general)).
479+
For an *operator_declaration* in an interface the *operator_body* may only be a block body ([§15.6.1](classes.md#1561-general)) or an expression body ([§15.6.1](classes.md#1561-general)).
480480
481481
It is a compile-time error for an interface to declare a conversion, equality, or inequality operator.
482482
@@ -514,7 +514,7 @@ It is an error to declare a class type, struct type, or enum type within the sco
514514
>
515515
> *end example*
516516
517-
### 19.4.10 most specific implementation
517+
### 19.4.10 Most specific implementation
518518
519519
Every class and struct shall have a most specific implementation for every virtual member declared in all interfaces implemented by that type among the implementations appearing in the type or its direct and indirect interfaces. The ***most specific implementation*** is a unique implementation that is more specific than every other implementation.
520520
@@ -886,7 +886,7 @@ A *type_parameter_constraints_clause* on an explicit interface method implementa
886886
> Explicit interface member implementations serve two primary purposes:
887887
>
888888
> - Because explicit interface member implementations are not accessible through class or struct instances, they allow interface implementations to be excluded from the public interface of a class or struct. This is particularly useful when a class or struct implements an internal interface that is of no interest to a consumer of that class or struct.
889-
> - Explicit interface member implementations allow disambiguation of interface members with the same signature. Without explicit interface member implementations it would be impossible for a class, struct, or interface to have different implementations of interface members with the same signature and return type, as would it be impossible for a class, struct, or interface to have any implementation at all of interface members with the same signature but with different return types.
889+
> - Explicit interface member implementations allow disambiguation of interface members with the same signature. Without explicit interface member implementations it would be impossible for a class, struct, or interface to have different implementations of interface members with the same signature and return type; and it would be impossible for a class, struct, or interface to have any implementation at all of interface members with the same signature but with different return types.
890890
>
891891
> *end note*
892892
@@ -1066,7 +1066,7 @@ When a generic method implicitly implements an interface method, the constraints
10661066
10671067
### 19.6.5 Interface mapping
10681068
1069-
A class or struct shall provide implementations of all abstract members of the interfaces that are listed in the base class list of the class or struct. The process of locating implementations of interface members in an implementing class or struct is known as ***interface mapping***.
1069+
A class or struct shall provide implementations for all abstract members of the interfaces that are listed in the base class list of the class or struct which are not implemented in any of those listed interfaces. The process of locating implementations of interface members in an implementing class or struct is known as ***interface mapping***.
10701070
10711071
Interface mapping for a class or struct `C` locates an implementation for each member of each interface specified in the base class list of `C`. The implementation of a particular interface member `I.M`, where `I` is the interface in which the member `M` is declared, is determined by examining each class, interface, or struct `S`, starting with `C` and repeating for each successive base class and implemented interface of `C`, until a match is located:
10721072
@@ -1463,7 +1463,7 @@ When a class implements an interface, it implicitly also implements all that int
14631463
14641464
### 19.6.8 Abstract classes and interfaces
14651465
1466-
Like a non-abstract class, an abstract class shall provide implementations of all abstract members of the interfaces that are listed in the base class list of the class. However, an abstract class is permitted to map interface methods onto abstract methods.
1466+
Like a non-abstract class, an abstract class shall provide implementations of all abstract members of the interfaces that are listed in the base class list of the class which are not implemented in any of those listed interfaces. However, an abstract class is permitted to map interface methods onto abstract methods.
14671467
14681468
> *Example*:
14691469
>
@@ -1479,7 +1479,7 @@ Like a non-abstract class, an abstract class shall provide implementations of al
14791479
> {
14801480
> public abstract void F();
14811481
> public abstract void G();
1482-
> }
1482+
> }
14831483
> ```
14841484
>
14851485
> Here, the implementation of `IMethods` maps `F` and `G` onto abstract methods, which shall be overridden in non-abstract classes that derive from `C`.
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# Sample: Expanded Interfaces
2+
3+
Simple test to check that interfaces can now declare more kinds of members and contain
4+
implementations.
5+
6+
The grammar for all interface members now uses the same productions as for classes,
7+
with any differences being handled in prose, as such this test does not test
8+
these differences.
9+
10+
Note: No Antlr custom predicates have currently been developed for any interface
11+
semantic rules as they are not key to parsing.

0 commit comments

Comments
 (0)