From 7efbadf58a85627e71f33996a324deae8bce8492 Mon Sep 17 00:00:00 2001 From: Rex Jaeschke Date: Mon, 2 Mar 2026 07:40:50 -0500 Subject: [PATCH 01/10] support file-local types Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: 21570b74-c6f5-4fc5-ab6d-7546918d6ddb Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: 361b9a77-2b4c-45e6-969f-e6785c47f27e --- standard/lexical-structure.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/standard/lexical-structure.md b/standard/lexical-structure.md index 86a73301c..e5e78f2dd 100644 --- a/standard/lexical-structure.md +++ b/standard/lexical-structure.md @@ -604,7 +604,7 @@ keyword | 'byte' | 'case' | 'catch' | 'char' | 'checked' | 'class' | 'const' | 'continue' | 'decimal' | DEFAULT | 'delegate' | 'do' | 'double' | 'else' | 'enum' - | 'event' | 'explicit' | 'extern' | FALSE | 'finally' + | 'event' | 'explicit' | 'extern' | FALSE | 'file' | 'finally' | 'fixed' | 'float' | 'for' | 'foreach' | 'goto' | 'if' | 'implicit' | 'in' | 'int' | 'interface' | 'internal' | 'is' | 'lock' | 'long' | 'namespace' From 389244f4c0acddeaac33df82c943419f13e76465 Mon Sep 17 00:00:00 2001 From: Rex Jaeschke Date: Mon, 2 Mar 2026 07:43:21 -0500 Subject: [PATCH 02/10] support file-local types Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: 21570b74-c6f5-4fc5-ab6d-7546918d6ddb Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: 361b9a77-2b4c-45e6-969f-e6785c47f27e --- standard/expressions.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/standard/expressions.md b/standard/expressions.md index 142e87ff6..17185d6af 100644 --- a/standard/expressions.md +++ b/standard/expressions.md @@ -378,6 +378,8 @@ A member lookup of a name `N` with `K` type arguments in a type `T` is proces - If `T` is a type parameter, then the set is the union of the sets of accessible members named `N` in each of the types specified as a primary constraint or secondary constraint ([§15.2.5](classes.md#1525-type-parameter-constraints)) for `T`, along with the set of accessible members named `N` in `object`. - Otherwise, the set consists of all accessible ([§7.4](basic-concepts.md#74-member-access)) members named `N` in `T`, including inherited members and the accessible members named `N` in `object`. If `T` is a constructed type, the set of members is obtained by substituting type arguments as described in [§15.3.3](classes.md#1533-members-of-constructed-types). Members that include an `override` modifier are excluded from the set. - Next, if `K` is zero, all nested types whose declarations include type parameters are removed. If `K` is not zero, all members with a different number of type parameters are removed. When `K` is zero, methods having type parameters are not removed, since the type inference process ([§12.6.3](expressions.md#1263-type-inference)) might be able to infer the type arguments. +- Next, let *F* be the compilation unit that contains the expression where member lookup is occurring. All members that are file-local types and are not declared in *F* are removed from the set. +- Next, if the set of accessible members contains file-local types, all members that are not file-local types are removed from the set. - Next, if the member is invoked, all non-invocable members are removed from the set. - Next, members that are hidden by other members are removed from the set. For every member `S.M` in the set, where `S` is the type in which the member `M` is declared, the following rules are applied: - If `M` is a constant, field, property, event, or enumeration member, then all members declared in a base type of `S` are removed from the set. From 79166010c63a4e82690c1cb47ca3ed979d58a367 Mon Sep 17 00:00:00 2001 From: Rex Jaeschke Date: Mon, 2 Mar 2026 07:46:29 -0500 Subject: [PATCH 03/10] support file-local types Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: 21570b74-c6f5-4fc5-ab6d-7546918d6ddb Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: 361b9a77-2b4c-45e6-969f-e6785c47f27e --- standard/namespaces.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/standard/namespaces.md b/standard/namespaces.md index 8f1e2df22..598486cb8 100644 --- a/standard/namespaces.md +++ b/standard/namespaces.md @@ -372,6 +372,8 @@ A *global_using_static_directive* only imports members and types declared direct Ambiguities between multiple *global_using_namespace_directive*s and *global_using_static_directives* are discussed in [§14.5.3](namespaces.md#1453-global-using-namespace-directives). +It is a compile-time error to use a file-local type in a *global_using_static_directive*. + ## 14.6 Using directives ### 14.6.1 General From 834f3fe58bdcab5f1c30ec61bc564b78e550eed7 Mon Sep 17 00:00:00 2001 From: Rex Jaeschke Date: Mon, 2 Mar 2026 07:51:09 -0500 Subject: [PATCH 04/10] support file-local types Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: 21570b74-c6f5-4fc5-ab6d-7546918d6ddb Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: 361b9a77-2b4c-45e6-969f-e6785c47f27e --- standard/classes.md | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/standard/classes.md b/standard/classes.md index 7f702e22f..7699380ab 100644 --- a/standard/classes.md +++ b/standard/classes.md @@ -49,6 +49,7 @@ class_modifier | 'abstract' | 'sealed' | 'static' + | 'file' | unsafe_modifier // unsafe code support ; ``` @@ -61,10 +62,22 @@ 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)). +It is a compile-time error for any of the `public`, `protected`, `internal`, and `private` modifiers to be combined with the `file` 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. A compilation unit containing a `file`-modified type shall not also contain a type declaration having the same name but without the `file` 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***. + +The implementation shall guarantee that file-local types with the same name declared in different compilation units, are distinct at runtime. The implementation shall guarantee that a file-local type with the same name as a non-file-local type declared in different compilation units, are distinct at runtime. + +A file-local class that is an attribute type may be used an as 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: @@ -249,6 +262,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)). +A file-local class shall not be used as a base type of a non-file-local 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 @@ -863,6 +878,8 @@ class_member_declaration ; ``` +The signature of a member in a non-file-local type shall not contain a file-local type. + 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)). From 5bf832f91750d3d0d8be6046cb53622edc210909 Mon Sep 17 00:00:00 2001 From: Rex Jaeschke Date: Mon, 2 Mar 2026 07:53:03 -0500 Subject: [PATCH 05/10] support file-local types Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: 21570b74-c6f5-4fc5-ab6d-7546918d6ddb Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: 361b9a77-2b4c-45e6-969f-e6785c47f27e --- standard/structs.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/standard/structs.md b/standard/structs.md index 44c310734..4fcd9350a 100644 --- a/standard/structs.md +++ b/standard/structs.md @@ -60,6 +60,7 @@ struct_modifier | 'internal' | 'private' | 'readonly' + | 'file' | unsafe_modifier // unsafe code support ; ``` @@ -68,6 +69,8 @@ struct_modifier It is a compile-time error for the same modifier to appear multiple times in a struct declaration. +It is a compile-time error for any of the `public`, `protected`, `internal`, and `private` modifiers to be combined with the `file` modifier. + Except for `readonly`, the modifiers of a struct declaration have the same meaning as those of a class declaration ([§15.2.2](classes.md#1522-class-modifiers)). The `readonly` modifier indicates that the *struct_declaration* declares a type whose instances are immutable. From 4da3862c205052f51552dfa50f9addf2c40a1cee Mon Sep 17 00:00:00 2001 From: Rex Jaeschke Date: Mon, 2 Mar 2026 07:56:09 -0500 Subject: [PATCH 06/10] support file-local types Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: 21570b74-c6f5-4fc5-ab6d-7546918d6ddb Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: 361b9a77-2b4c-45e6-969f-e6785c47f27e --- standard/interfaces.md | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/standard/interfaces.md b/standard/interfaces.md index aeaa0015a..becc59194 100644 --- a/standard/interfaces.md +++ b/standard/interfaces.md @@ -40,6 +40,7 @@ interface_modifier | 'protected' | 'internal' | 'private' + | 'file' | unsafe_modifier // unsafe code support ; ``` @@ -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 From fe54debfa946bf03e162eb5a05fdf06463eb1d31 Mon Sep 17 00:00:00 2001 From: Rex Jaeschke Date: Mon, 2 Mar 2026 07:59:39 -0500 Subject: [PATCH 07/10] support file-local types Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: 21570b74-c6f5-4fc5-ab6d-7546918d6ddb Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: 361b9a77-2b4c-45e6-969f-e6785c47f27e --- standard/enums.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/standard/enums.md b/standard/enums.md index 35dbeb53b..4ce22401c 100644 --- a/standard/enums.md +++ b/standard/enums.md @@ -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 From b20138d348069c45a1d82f88ba4f7de4231ad334 Mon Sep 17 00:00:00 2001 From: Rex Jaeschke Date: Mon, 2 Mar 2026 08:02:30 -0500 Subject: [PATCH 08/10] support file-local types Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: 21570b74-c6f5-4fc5-ab6d-7546918d6ddb Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: 361b9a77-2b4c-45e6-969f-e6785c47f27e --- standard/delegates.md | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/standard/delegates.md b/standard/delegates.md index c76c88799..a0f7d92a9 100644 --- a/standard/delegates.md +++ b/standard/delegates.md @@ -29,6 +29,7 @@ delegate_modifier | 'protected' | 'internal' | 'private' + | 'file' | unsafe_modifier // unsafe code support ; ``` @@ -41,7 +42,9 @@ 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 delegate’s type name is *identifier*. From 0f6cbadeb19067a0a9cb987b2049589860033bf1 Mon Sep 17 00:00:00 2001 From: Bill Wagner Date: Fri, 1 May 2026 17:23:50 -0400 Subject: [PATCH 09/10] Review and update changes `file` should be a contextual keyword. Fix some other errors of omission. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: 21570b74-c6f5-4fc5-ab6d-7546918d6ddb Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: 361b9a77-2b4c-45e6-969f-e6785c47f27e --- standard/classes.md | 8 +++++--- standard/lexical-structure.md | 20 ++++++++++---------- 2 files changed, 15 insertions(+), 13 deletions(-) diff --git a/standard/classes.md b/standard/classes.md index 7699380ab..bec1b213d 100644 --- a/standard/classes.md +++ b/standard/classes.md @@ -68,15 +68,15 @@ When a partial type declaration ([§15.2.7](classes.md#1527-partial-type-declara 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. A compilation unit containing a `file`-modified type shall not also contain a type declaration having the same name but without the `file` modifier. +The `file` modifier specifies that the type being declared is local to its parent compilation unit. A compilation unit containing a `file`-modified type shall not also contain a type declaration having the same name but without the `file` modifier. (`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***. -The implementation shall guarantee that file-local types with the same name declared in different compilation units, are distinct at runtime. The implementation shall guarantee that a file-local type with the same name as a non-file-local type declared in different compilation units, are distinct at runtime. +The implementation shall guarantee that two type declarations are distinct at runtime when either both are file-local types with the same name declared in different compilation units, or one is a file-local type and the other is a non-file-local type with the same name. -A file-local class that is an attribute type may be used an as attribute within both file-local types and non-file-local types, just as if the attribute type were a non-file-local class. +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 @@ -800,6 +800,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 a partial type, either all parts shall include the `file` modifier and be declared in the same compilation unit, or no part shall include the `file` modifier. + 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. diff --git a/standard/lexical-structure.md b/standard/lexical-structure.md index e5e78f2dd..d20b9725b 100644 --- a/standard/lexical-structure.md +++ b/standard/lexical-structure.md @@ -604,7 +604,7 @@ keyword | 'byte' | 'case' | 'catch' | 'char' | 'checked' | 'class' | 'const' | 'continue' | 'decimal' | DEFAULT | 'delegate' | 'do' | 'double' | 'else' | 'enum' - | 'event' | 'explicit' | 'extern' | FALSE | 'file' | 'finally' + | 'event' | 'explicit' | 'extern' | FALSE | 'finally' | 'fixed' | 'float' | 'for' | 'foreach' | 'goto' | 'if' | 'implicit' | 'in' | 'int' | 'interface' | 'internal' | 'is' | 'lock' | 'long' | 'namespace' @@ -623,15 +623,15 @@ A ***contextual keyword*** is an identifier-like sequence of characters that has ```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' ; ``` From 259418cb5e5f3189dcfc93b0f52bdac185dd29f7 Mon Sep 17 00:00:00 2001 From: Bill Wagner Date: Tue, 17 Nov 2026 16:41:40 -0500 Subject: [PATCH 10/10] Additional normative rules on file local types. Add additional for file local types. --- standard/basic-concepts.md | 10 ++++++++-- standard/classes.md | 28 ++++++++++++++++++++++------ standard/delegates.md | 2 ++ standard/expressions.md | 8 +++++--- standard/interfaces.md | 2 ++ standard/namespaces.md | 2 +- 6 files changed, 40 insertions(+), 12 deletions(-) diff --git a/standard/basic-concepts.md b/standard/basic-concepts.md index 845a86529..62beba210 100644 --- a/standard/basic-concepts.md +++ b/standard/basic-concepts.md @@ -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. @@ -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 @@ -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). diff --git a/standard/classes.md b/standard/classes.md index bec1b213d..597aa3d18 100644 --- a/standard/classes.md +++ b/standard/classes.md @@ -62,19 +62,35 @@ 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)). -It is a compile-time error for any of the `public`, `protected`, `internal`, and `private` modifiers to be combined with the `file` modifier. +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. A compilation unit containing a `file`-modified type shall not also contain a type declaration having the same name but without the `file` modifier. (`file` is a contextual keyword (§6.4.4) that has special meaning when used as a top-level type modifier.) +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***. -The implementation shall guarantee that two type declarations are distinct at runtime when either both are file-local types with the same name declared in different compilation units, or one is a file-local type and the other is a non-file-local type with the same name. +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. @@ -262,7 +278,7 @@ 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)). -A file-local class shall not be used as a base type of a non-file-local class. +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. @@ -800,7 +816,7 @@ 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 a partial type, either all parts shall include the `file` modifier and be declared in the same compilation unit, or no part shall include the `file` modifier. +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. @@ -880,7 +896,7 @@ class_member_declaration ; ``` -The signature of a member in a non-file-local type shall not contain a file-local type. +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: diff --git a/standard/delegates.md b/standard/delegates.md index a0f7d92a9..71f6e0175 100644 --- a/standard/delegates.md +++ b/standard/delegates.md @@ -46,6 +46,8 @@ The `public`, `protected`, `internal`, and `private` modifiers control the acces 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*. 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. diff --git a/standard/expressions.md b/standard/expressions.md index 17185d6af..c935ceb27 100644 --- a/standard/expressions.md +++ b/standard/expressions.md @@ -368,6 +368,8 @@ A ***lifted operator*** permits predefined and user-defined operators that opera 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. @@ -378,8 +380,6 @@ A member lookup of a name `N` with `K` type arguments in a type `T` is proces - If `T` is a type parameter, then the set is the union of the sets of accessible members named `N` in each of the types specified as a primary constraint or secondary constraint ([§15.2.5](classes.md#1525-type-parameter-constraints)) for `T`, along with the set of accessible members named `N` in `object`. - Otherwise, the set consists of all accessible ([§7.4](basic-concepts.md#74-member-access)) members named `N` in `T`, including inherited members and the accessible members named `N` in `object`. If `T` is a constructed type, the set of members is obtained by substituting type arguments as described in [§15.3.3](classes.md#1533-members-of-constructed-types). Members that include an `override` modifier are excluded from the set. - Next, if `K` is zero, all nested types whose declarations include type parameters are removed. If `K` is not zero, all members with a different number of type parameters are removed. When `K` is zero, methods having type parameters are not removed, since the type inference process ([§12.6.3](expressions.md#1263-type-inference)) might be able to infer the type arguments. -- Next, let *F* be the compilation unit that contains the expression where member lookup is occurring. All members that are file-local types and are not declared in *F* are removed from the set. -- Next, if the set of accessible members contains file-local types, all members that are not file-local types are removed from the set. - Next, if the member is invoked, all non-invocable members are removed from the set. - Next, members that are hidden by other members are removed from the set. For every member `S.M` in the set, where `S` is the type in which the member `M` is declared, the following rules are applied: - If `M` is a constant, field, property, event, or enumeration member, then all members declared in a base type of `S` are removed from the set. @@ -1705,6 +1705,8 @@ A *simple_name* is either of the form `I` or of the form `I`, 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: @@ -1834,7 +1836,7 @@ A *member_access* is either of the form `E.I` or of the form `E.I *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. diff --git a/standard/namespaces.md b/standard/namespaces.md index 598486cb8..70bc8499b 100644 --- a/standard/namespaces.md +++ b/standard/namespaces.md @@ -1020,7 +1020,7 @@ A *qualified_alias_member* has one of two forms: - `N::I`, where `N` and `I` represent identifiers, and `` is a type argument list. (`e` is always at least one.) - `N::I`, where `N` and `I` represent identifiers. (In this case, `e` is considered to be zero.) -Using this notation, the meaning of a *qualified_alias_member* is determined as follows: +Using this notation, the meaning of a *qualified_alias_member* is determined as follows. The namespace searched for the right-hand identifier is subject to the file-local type filtering rules in [§7.7.1](basic-concepts.md#771-general). - If `N` is the identifier `global`, then the global namespace is searched for `I`: - If the global namespace contains a namespace named `I` and `e` is zero, then the *qualified_alias_member* refers to that namespace.