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
10 changes: 8 additions & 2 deletions standard/basic-concepts.md
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,8 @@ A declaration defines a name in the ***declaration space*** to which the declara
> *Note*: However, these declarations could introduce ambiguities if included in the same application. *end note*
- Two or more methods with the same name but distinct signatures are allowed in the same declaration space ([§7.5](basic-concepts.md#75-signatures-and-overloading)).
- Two or more type declarations with the same name but distinct numbers of type parameters are allowed in the same declaration space ([§7.7.2](basic-concepts.md#772-unqualified-names)).
- Two or more type declarations with the partial modifier in the same declaration space may share the same name, same number of type parameters and same classification (class, record class, struct, record struct, or interface). The keywords `record` and `record class` specify the same classification. In this case, the type declarations contribute to a single type and are themselves aggregated to form a single declaration space ([§15.2.7](classes.md#1527-partial-type-declarations)).
- A file-local type ([§15.2.2.1](classes.md#15221-general)) may share a name with a namespace or type declared entirely in other compilation units. Such entities are distinct.
- Two or more type declarations with the partial modifier in the same declaration space may share the same name, same number of type parameters and same classification (class, record class, struct, record struct, or interface). The keywords `record` and `record class` specify the same classification. Such declarations are combined as specified in [§15.2.7](classes.md#1527-partial-type-declarations), sharing a declaration space for each resulting type.
- A namespace declaration and a type declaration in the same declaration space can share the same name as long as the type declaration has at least one type parameter ([§7.7.2](basic-concepts.md#772-unqualified-names)).

There are several different types of declaration spaces, as described in the following.
Expand Down Expand Up @@ -947,6 +948,11 @@ A declaration of a new member hides an inherited member only within the scope of

Several contexts in a C# program require a *namespace_name* or a *type_name* to be specified.

Namespace and type name resolution, simple-name resolution ([§12.8.4](expressions.md#1284-simple-names)), member access ([§12.8.7](expressions.md#1287-member-access)), and qualified alias member resolution ([§14.9.1](namespaces.md#1491-general)) apply the following filtering rules. At each lookup step that considers namespace members or a set of imported members, candidates with the required name and number of type parameters are filtered before namespace or type selection and ambiguity checks:

- A file-local type is a candidate only in the compilation unit in which it is declared.
- If the candidate set includes a file-local type, only file-local types are retained.

```ANTLR
namespace_name
: namespace_or_type_name
Expand Down Expand Up @@ -1081,7 +1087,7 @@ Every namespace and type declaration has a ***fully qualified name,*** which uni
- If `N` is a member of the global namespace, its fully qualified name is `N`.
- Otherwise, its fully qualified name is `S.N`, where `S` is the fully qualified name of the namespace or type declaration in which `N` is declared.

In other words, the fully qualified name of `N` is the complete hierarchical path of identifiers and *generic_dimension_specifier*s that lead to `N`, starting from the global namespace. Because every member of a namespace or type shall have a unique name, it follows that the fully qualified name of a namespace or type declaration is always unique. It is a compile-time error for the same fully qualified name to refer to two distinct entities. In particular:
In other words, the fully qualified name of `N` is the complete hierarchical path of identifiers and *generic_dimension_specifier*s that lead to `N`, starting from the global namespace. Subject to the file-local type exception in [§7.2](basic-concepts.md#72-declarations), it is a compile-time error for the same fully qualified name to refer to two distinct entities. This exception also applies to types nested within those distinct types. In particular, for declarations to which the exception does not apply:

- It is an error for both a namespace declaration and a type declaration to have the same fully qualified name.
- It is an error for two different kinds of type declarations to have the same fully qualified name (for example, if both a struct and class declaration have the same fully qualified name).
Expand Down
35 changes: 35 additions & 0 deletions standard/classes.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ class_modifier
| 'abstract'
| 'sealed'
| 'static'
| 'file'
| unsafe_modifier // unsafe code support
;
```
Expand All @@ -61,10 +62,38 @@ The `new` modifier is permitted on nested classes. It specifies that the class h

The `public`, `protected`, `internal`, and `private` modifiers control the accessibility of the class. Depending on the context in which the class declaration occurs, some of these modifiers might not be permitted ([§7.4.2](basic-concepts.md#742-declared-accessibility)).

No declaration of a file-local type shall include an accessibility modifier.

When a partial type declaration ([§15.2.7](classes.md#1527-partial-type-declarations)) includes an accessibility specification (via the `public`, `protected`, `internal`, and `private` modifiers), that specification shall agree with all other parts that include an accessibility specification. If no part of a partial type includes an accessibility specification, the type is given the appropriate default accessibility ([§7.4.2](basic-concepts.md#742-declared-accessibility)).

The `abstract`, `sealed`, and `static` modifiers are discussed in the following subclauses.

The `file` modifier specifies that the type being declared is local to its parent compilation unit. Declaration identity and name conflicts for file-local types are specified in [§7.2](basic-concepts.md#72-declarations). (`file` is a contextual keyword (§6.4.4) that has special meaning when used as a top-level type modifier.)

The `file` modifier shall only appear in a type declaration for a top-level type.

When a type declaration contains the `file` modifier, that type is said to be a ***file-local type***.

Distinct types under the rules of [§7.2](basic-concepts.md#72-declarations) shall be distinct at runtime, including file-local types with the same fully qualified name. The name and accessibility of a file-local type in metadata are implementation-defined.

A type ***involves a file-local type*** if it is a file-local type, is nested in a type that involves a file-local type, or has any of the following that involves a file-local type:

- An element type, for an array or pointer type.
- An underlying type, for a nullable value type.
- A type argument, for a constructed type.
- An element type, for a tuple type.
- A parameter or return type, for a function pointer type.

For a type that is neither file-local nor nested within a file-local type, the following types shall not involve a file-local type:

- Its direct base class, if it is a class, or its explicit base interfaces, if it is an interface.
- The constraint types specified for its type parameters or for the type parameters of its members.
- The types of constants, fields, properties, events, and indexers declared in it.
- The parameter and return types of function members declared in it.
- Its parameter and return types, if it is a delegate.

A file-local class that is an attribute type may be used as an attribute within both file-local types and non-file-local types, just as if the attribute type were a non-file-local class.

#### 15.2.2.2 Abstract classes

The `abstract` modifier is used to indicate that a class is incomplete and that it is intended to be used only as a base class. An ***abstract class*** differs from a ***non-abstract class*** in the following ways:
Expand Down Expand Up @@ -249,6 +278,8 @@ The direct base class of a class type shall be at least as accessible as the cla

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)).

The file-local type restrictions ([§15.2.2.1](classes.md#15221-general)) apply to the direct base class.

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.

> *Example*: The following
Expand Down Expand Up @@ -785,6 +816,8 @@ The modifier `partial` is used when defining a class, struct, or interface type

Each part of a ***partial type*** declaration shall include a `partial` modifier and shall be declared in the same namespace or containing type as the other parts. The `partial` modifier indicates that additional parts of the type declaration might exist elsewhere, but the existence of such additional parts is not a requirement; it is valid for the only declaration of a type to include the `partial` modifier. It is valid for only one declaration of a partial type to include the base class or implemented interfaces. However, all declarations of a base class or implemented interfaces shall match, including the nullability of any specified type arguments.

For top-level partial type declarations with the same namespace, name, number of type parameters, and classification ([§7.2](basic-concepts.md#72-declarations)), each compilation unit containing a declaration with the `file` modifier contributes a distinct file-local type consisting of the matching declarations in that compilation unit. Matching declarations in compilation units containing no such `file` declaration contribute to a separate non-file-local type. The modifier restrictions for file-local types apply to all parts of a file-local type.

All parts of a partial type shall be compiled together such that the parts can be merged at compile-time. Partial types specifically do not allow already compiled types to be extended.

Nested types may be declared in multiple parts by using the `partial` modifier. Typically, the containing type is declared using `partial` as well, and each part of the nested type is declared in a different part of the containing type.
Expand Down Expand Up @@ -863,6 +896,8 @@ class_member_declaration
;
```

The file-local type restrictions ([§15.2.2.1](classes.md#15221-general)) apply to members declared in a class.

The members of a class are divided into the following categories:

- Constants, which represent constant values associated with the class ([§15.4](classes.md#154-constants)).
Expand Down
7 changes: 6 additions & 1 deletion standard/delegates.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ delegate_modifier
| 'protected'
| 'internal'
| 'private'
| 'file'
| unsafe_modifier // unsafe code support
;
```
Expand All @@ -41,7 +42,11 @@ A delegate declaration that supplies a *variant_type_parameter_list* is a generi

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).

The `public`, `protected`, `internal`, and `private` modifiers control the accessibility of the delegate type. Depending on the context in which the delegate declaration occurs, some of these modifiers might not be permitted ([§7.4.2](basic-concepts.md#742-declared-accessibility)).
The `public`, `protected`, `internal`, and `private` modifiers control the accessibility of the delegate type. Depending on the context in which the delegate declaration occurs, some of these modifiers might not be permitted ([§7.4.2](basic-concepts.md#742-declared-accessibility)). It is a compile-time error for any of the `public`, `protected`, `internal`, and `private` modifiers to be combined with the `file` modifier.

The modifier `file` has the same meaning as that for a class declaration ([§15.2.2](classes.md#1522-class-modifiers)).

The file-local type restrictions ([§15.2.2.1](classes.md#15221-general)) apply to the delegate's parameter types, return type, and type parameter constraints.

The delegate’s type name is *identifier*.

Expand Down
3 changes: 3 additions & 0 deletions standard/enums.md
Original file line number Diff line number Diff line change
Expand Up @@ -85,11 +85,14 @@ enum_modifier
| 'protected'
| 'internal'
| 'private'
| 'file'
;
```

It is a compile-time error for the same modifier to appear multiple times in an enum declaration.

It is a compile-time error for any of the `public`, `protected`, `internal`, and `private` modifiers to be combined with the `file` modifier.

The modifiers of an enum declaration have the same meaning as those of a class declaration ([§15.2.2](classes.md#1522-class-modifiers)). However, the `abstract`, and `sealed`, and `static` modifiers are not permitted in an enum declaration. Enums cannot be abstract and do not permit derivation.

## 20.4 Enum members
Expand Down
6 changes: 5 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 @@ -368,6 +368,8 @@

A member lookup is the process whereby the meaning of a name in the context of a type is determined. A member lookup can occur as part of evaluating a *simple_name* ([§12.8.4](expressions.md#1284-simple-names)) or a *member_access* ([§12.8.7](expressions.md#1287-member-access)) in an expression. If the *simple_name* or *member_access* occurs as the *primary_expression* of an *invocation_expression* ([§12.8.10.2](expressions.md#128102-method-invocations)), the member is said to be *invoked*.

Lookup of namespace members follows [§7.7.1](basic-concepts.md#771-general) and [§12.8.7](expressions.md#1287-member-access), including the file-local type filtering rules.

If a member is a method or event, or if it is a constant, field or property of either a delegate type ([§21](delegates.md#21-delegates)) or the type `dynamic` ([§8.2.4](types.md#824-the-dynamic-type)), then the member is said to be *invocable.*

Member lookup considers not only the name of a member but also the number of type parameters the member has and whether the member is accessible. For the purposes of member lookup, generic methods and nested generic types have the number of type parameters indicated in their respective declarations and all other members have zero type parameters.
Expand Down Expand Up @@ -1703,6 +1705,8 @@

For the namespace lookup steps in this subclause and [§7.7.1](basic-concepts.md#771-general), let *D* be the set of directives considered at namespace `N`. If `N` is the global namespace, *D* consists of the *extern_alias_directive*s and *using_directive*s in the containing compilation unit, together with the *global_using_directive*s in all compilation units in the program. Otherwise, *D* consists of the *extern_alias_directive*s and *using_directive*s in the enclosing namespace declaration for `N`, if any. Only directives whose scope includes the location of the name being resolved are considered. The exclusions when resolving directive targets are specified in [§14.5](namespaces.md#145-global-using-directives) and [§14.6](namespaces.md#146-using-directives).

Namespace members and imported members are subject to the file-local type filtering rules in [§7.7.1](basic-concepts.md#771-general).

> *Note*: Global using directives participate at the global-namespace step, not at each inner-namespace step. Their scope includes nested namespaces, but lookup in an inner namespace can find a declaration or import before reaching the global namespace. *end note*

The *simple_name* is evaluated and classified as follows:
Expand Down Expand Up @@ -1832,7 +1836,7 @@

A *member_access* with a *primary_expression* of type `dynamic` is dynamically bound ([§12.3.3](expressions.md#1233-dynamic-binding)). In this case, the member access is classified as a property access of type `dynamic`. The rules below to determine the meaning of the *member_access* are then applied at run-time, using the run-time type instead of the compile-time type of the *primary_expression*. If this run-time classification leads to a method group, then the member access shall be the *primary_expression* of an *invocation_expression*.

The *member_access* is evaluated and classified as follows:
The *member_access* is evaluated and classified as follows, subject to the file-local type filtering rules in [§7.7.1](basic-concepts.md#771-general) when `E` is a namespace:

- If `e` is zero and `E` is a namespace and `E` contains a nested namespace with name `I`, then the result is that namespace.
- Otherwise, if `E` is a namespace and `E` contains an accessible type having name `I` and `K` type parameters, then the result is that type constructed with the given type arguments.
Expand Down
7 changes: 7 additions & 0 deletions standard/interfaces.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ interface_modifier
| 'protected'
| 'internal'
| 'private'
| 'file'
| unsafe_modifier // unsafe code support
;
```
Expand All @@ -52,6 +53,10 @@ The `new` modifier is only permitted on interfaces defined within a class. It sp

The `public`, `protected`, `internal`, and `private` modifiers control the accessibility of the interface. Depending on the context in which the interface declaration occurs, only some of these modifiers might be permitted ([§7.4.2](basic-concepts.md#742-declared-accessibility)). When a partial type declaration ([§15.2.7](classes.md#1527-partial-type-declarations)) includes an accessibility specification (via the `public`, `protected`, `internal`, and `private` modifiers), the rules in [§15.2.2](classes.md#1522-class-modifiers) apply.

It is a compile-time error for any of the `public`, `protected`, `internal`, and `private` modifiers to be combined with the `file` modifier.

The modifier `file` is described in [§15.2.2](classes.md#1522-class-modifiers).

### 19.2.3 Variant type parameter lists

#### 19.2.3.1 General
Expand Down Expand Up @@ -144,6 +149,8 @@ For a constructed interface type, the explicit base interfaces are formed by tak

The explicit base interfaces of an interface shall be at least as accessible as the interface itself ([§7.4.5](basic-concepts.md#745-accessibility-constraints)).

The file-local type restrictions ([§15.2.2.1](classes.md#15221-general)) apply to the explicit base interfaces.

> *Note*: For example, it is a compile-time error to specify a `private` or `internal` interface in the *interface_base* of a `public` interface. *end note*

It is a compile-time error for an interface to directly or indirectly inherit from itself.
Expand Down
18 changes: 9 additions & 9 deletions standard/lexical-structure.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
Conceptually speaking, a program is compiled using three steps:

1. Transformation, which converts a file from a particular character repertoire and encoding scheme into a sequence of Unicode characters.
1. Lexical analysis, which translates a stream of Unicode input characters into a stream of tokens.

Check warning on line 10 in standard/lexical-structure.md

View workflow job for this annotation

GitHub Actions / word-converter

Markdown to Word Converter - MDC032

Line length 85 > maximum 83; | PP_Start_Line_Character PP_Whitespace? '-' PP_Whitespace? PP_End_Line_Character
1. Syntactic analysis, which translates the stream of tokens into executable code.

Apart from accepting UTF-8 encoded input (as required by [§5](conformance.md#5-conformance), a conforming implementation may choose to accept and transform additional character encoding schemes (such as UTF-16, UTF-32, or non-Unicode character mappings).
Expand Down Expand Up @@ -623,15 +623,15 @@

```ANTLR
contextual_keyword
: 'add' | 'alias' | 'and' | 'ascending' | 'async'
| 'await' | 'by' | 'Cdecl' | 'descending' | 'dynamic'
| 'equals' | 'Fastcall' | 'from' | 'get' | 'global'
| 'group' | 'init' | 'into' | 'join' | 'let'
| 'managed' | 'nameof' | 'nint' | 'not' | 'notnull'
| 'nuint' | 'on' | 'or' | 'orderby' | 'partial'
| 'record' | 'remove' | 'select' | 'set' | 'Stdcall'
| 'Thiscall' | 'unmanaged' | 'value' | 'var' | 'when'
| 'where' | 'yield'
: 'add' | 'alias' | 'and' | 'ascending' | 'async'
| 'await' | 'by' | 'Cdecl' | 'descending' | 'dynamic'
| 'equals' | 'Fastcall' | 'file' | 'from' | 'get'
| 'global' | 'group' | 'init' | 'into' | 'join'
| 'let' | 'managed' | 'nameof' | 'nint' | 'not'
| 'notnull' | 'nuint' | 'on' | 'or' | 'orderby'
| 'partial' | 'record' | 'remove' | 'select' | 'set'
| 'Stdcall' | 'Thiscall' | 'unmanaged' | 'value' | 'var'
| 'when' | 'where' | 'yield'
;
```

Expand Down
Loading
Loading