Skip to content

Commit f36f8ed

Browse files
Nigel-Ecmajskeet
authored andcommitted
[DTW.4]
- Update namespace_or_type_name & unbound_type_name
1 parent ccd03b6 commit f36f8ed

27 files changed

+13489
-13660
lines changed
Binary file not shown.

standard/basic-concepts.md

Lines changed: 54 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -874,54 +874,82 @@ type_name
874874
;
875875
876876
namespace_or_type_name
877-
: identifier type_argument_list?
878-
| namespace_or_type_name '.' identifier type_argument_list?
879-
| qualified_alias_member
877+
: identifier type_argument_list? ('.' identifier type_argument_list?)*
878+
| qualified_alias_member ('.' identifier type_argument_list?)*
880879
;
881880
```
882881
883882
A *namespace_name* is a *namespace_or_type_name* that refers to a namespace.
884883

885884
Following resolution as described below, the *namespace_or_type_name* of a *namespace_name* shall refer to a namespace, or otherwise a compile-time error occurs. No type arguments ([§8.4.2](types.md#842-type-arguments)) can be present in a *namespace_name* (only types can have type arguments).
886885

887-
A *type_name* is a *namespace_or_type_name* that refers to a type. Following resolution as described below, the *namespace_or_type_name* of a *type_name* shall refer to a type, or otherwise a compile-time error occurs.
886+
A *type_name* is a *namespace_or_type_name* that refers to a type.
888887

889-
If the *namespace_or_type_name* is a *qualified_alias_member* its meaning is as described in [§14.8.1](namespaces.md#1481-general). Otherwise, a *namespace_or_type_name* has one of four forms:
888+
Following resolution as described below, the *namespace_or_type_name* of a *type_name* shall refer to a type, or otherwise a compile-time error occurs.
889+
890+
A *namespace_or_type_name* refers to a type or a namespace. Resolution to a particular namespace or type involves two steps based on dividing the grammar into an leading part, being one of the grammar fragments:
891+
892+
- `identifier type_argument_list?`
893+
- `qualified_alias_member`
894+
895+
and a trailing part, being the grammar fragment:
896+
897+
- `('.' identifier type_argument_list?)*`
898+
899+
First the leading part is resolved to determine `R₀`, the starting namespace or type.
900+
901+
If the leading part of the *namespace_or_type_name* is a *qualified_alias_member*, then `R₀` is the namespace or type identified by resolving that as described in *Qualified alias member* [§14.8.1](namespaces.md#1481-general).
902+
903+
Otherwise, the leading part, being the grammar fragment *identifier type_argument_list?*, will have one of the forms:
890904

891905
- `I`
892906
- `I<A₁, ..., Aₓ>`
893-
- `N.I`
894-
- `N.I<A₁, ..., Aₓ>`
895907

896-
where `I` is a single identifier, `N` is a *namespace_or_type_name* and `<A₁, ..., Aₓ>` is an optional *type_argument_list*. When no *type_argument_list* is specified, consider `x` to be zero.
908+
where:
909+
910+
- `I` is a single identifier; and
911+
- `<A₁, ..., Aₓ>` is a *type_argument_list*, when no *type_argument_list* is specified consider `x` to be zero.
897912

898-
The meaning of a *namespace_or_type_name* is determined as follows:
913+
`R₀` is determined as follows:
899914

900-
- If the *namespace_or_type_name* is a *qualified_alias_member*, the meaning is as specified in [§14.8.1](namespaces.md#1481-general).
901-
- Otherwise, if the *namespace_or_type_name* is of the form `I` or of the form `I<A₁, ..., Aₓ>`:
902-
- If `x` is zero and the *namespace_or_type_name* appears within a generic method declaration ([§15.6](classes.md#156-methods)) but outside the *attributes* of its *method-header,* and if that declaration includes a type parameter ([§15.2.3](classes.md#1523-type-parameters)) with name `I`, then the *namespace_or_type_name* refers to that type parameter.
903-
- Otherwise, if the *namespace_or_type_name* appears within a type declaration, then for each instance type `T` ([§15.3.2](classes.md#1532-the-instance-type)), starting with the instance type of that type declaration and continuing with the instance type of each enclosing class or struct declaration (if any):
904-
- If `x` is zero and the declaration of `T` includes a type parameter with name `I`, then the *namespace_or_type_name* refers to that type parameter.
905-
- Otherwise, if the *namespace_or_type_name* appears within the body of the type declaration, and `T` or any of its base types contain a nested accessible type having name `I` and `x` type parameters, then the *namespace_or_type_name* refers to that type constructed with the given type arguments. If there is more than one such type, the type declared within the more derived type is selected.
915+
- If `x` is zero and the *namespace_or_type_name* appears within a generic method declaration ([§15.6](classes.md#156-methods)) but outside the *attributes* of its *method-header,* and if that declaration includes a type parameter ([§15.2.3](classes.md#1523-type-parameters)) with name `I`, then `R₀` refers to that type parameter.
916+
- Otherwise, if the *namespace_or_type_name* appears within a type declaration, then for each instance type `T` ([§15.3.2](classes.md#1532-the-instance-type)), starting with the instance type of that type declaration and continuing with the instance type of each enclosing class or struct declaration (if any):
917+
- If `x` is zero and the declaration of `T` includes a type parameter with name `I`, then `R₀` refers to that type parameter.
918+
- Otherwise, if the *namespace_or_type_name* appears within the body of the type declaration, and `T` or any of its base types contain a nested accessible type having name `I` and `x` type parameters, then `R₀` refers to that type constructed with the given type arguments. If there is more than one such type, the type declared within the more derived type is selected.
906919
> *Note*: Non-type members (constants, fields, methods, properties, indexers, operators, instance constructors, finalizers, and static constructors) and type members with a different number of type parameters are ignored when determining the meaning of the *namespace_or_type_name*. *end note*
907920
- Otherwise, for each namespace `N`, starting with the namespace in which the *namespace_or_type_name* occurs, continuing with each enclosing namespace (if any), and ending with the global namespace, the following steps are evaluated until an entity is located:
908921
- If `x` is zero and `I` is the name of a namespace in `N`, then:
909922
- If the location where the *namespace_or_type_name* occurs is enclosed by a namespace declaration for `N` and the namespace declaration contains an *extern_alias_directive* or *using_alias_directive* that associates the name `I` with a namespace or type, then the *namespace_or_type_name* is ambiguous and a compile-time error occurs.
910-
- Otherwise, the *namespace_or_type_name* refers to the namespace named `I` in `N`.
923+
- Otherwise, `R₀` refers to the namespace named `I` in `N`.
911924
- Otherwise, if `N` contains an accessible type having name `I` and `x` type parameters, then:
912925
- If `x` is zero and the location where the *namespace_or_type_name* occurs is enclosed by a namespace declaration for `N` and the namespace declaration contains an *extern_alias_directive* or *using_alias_directive* that associates the name `I` with a namespace or type, then the *namespace_or_type_name* is ambiguous and a compile-time error occurs.
913-
- Otherwise, the *namespace_or_type_name* refers to the type constructed with the given type arguments.
926+
- Otherwise, `R₀` refers to the type constructed with the given type arguments.
914927
- Otherwise, if the location where the *namespace_or_type_name* occurs is enclosed by a namespace declaration for `N`:
915-
- If `x` is zero and the namespace declaration contains an *extern_alias_directive* or *using_alias_directive* that associates the name `I` with an imported namespace or type, then the *namespace_or_type_name* refers to that namespace or type.
916-
- Otherwise, if the namespaces imported by the *using_namespace_directive*s of the namespace declaration contain exactly one type having name `I` and `x` type parameters, then the *namespace_or_type_name* refers to that type constructed with the given type arguments.
917-
- Otherwise, if the namespaces imported by the *using_namespace_directive*s of the namespace declaration contain more than one type having name `I` and `x` type parameters, then the *namespace_or_type_name* is ambiguous and an error occurs.
928+
- If `x` is zero and the namespace declaration contains an *extern_alias_directive* or *using_alias_directive* that associates the name `I` with an imported namespace or type, then `R₀` refers to that namespace or type.
929+
- Otherwise, if the namespaces imported by the *using_namespace_directive*s of the namespace declaration contain exactly one type having name `I` and `x` type parameters, then `R₀` refers to that type constructed with the given type arguments.
930+
- Otherwise, if the namespaces imported by the *using_namespace_directive*s of the namespace declaration contain more than one type having name `I` and `x` type parameters, then the *namespace_or_type_name* is ambiguous and a compile-time error occurs.
918931
- Otherwise, the *namespace_or_type_name* is undefined and a compile-time error occurs.
919-
- Otherwise, the *namespace_or_type_name* is of the form `N.I` or of the form `N.I<A₁, ..., Aₓ>`. `N` is first resolved as a *namespace_or_type_name*. If the resolution of `N` is not successful, a compile-time error occurs. Otherwise, `N.I` or `N.I<A₁, ..., Aₓ>` is resolved as follows:
920-
- If `x` is zero and `N` refers to a namespace and `N` contains a nested namespace with name `I`, then the *namespace_or_type_name* refers to that nested namespace.
921-
- Otherwise, if `N` refers to a namespace and `N` contains an accessible type having name `I` and `x` type parameters, then the *namespace_or_type_name* refers to that type constructed with the given type arguments.
922-
- Otherwise, if `N` refers to a (possibly constructed) class or struct type and `N` or any of its base classes contain a nested accessible type having name `I` and `x` type parameters, then the *namespace_or_type_name* refers to that type constructed with the given type arguments. If there is more than one such type, the type declared within the more derived type is selected.
923-
> *Note*: If the meaning of `N.I` is being determined as part of resolving the base class specification of `N` then the direct base class of `N` is considered to be `object` ([§15.2.4.2](classes.md#15242-base-classes)). *end note*
924-
- Otherwise, `N.I` is an invalid *namespace_or_type_name*, and a compile-time error occurs.
932+
933+
If `R₀` has been resolved successfully the trailing part of the *namespace_or_type_name* is resolved. The trailing grammar fragment consists of `k ≥ 0` repetitions, with each repetition further resolving the referenced namespace or type.
934+
935+
If `k` is zero, i.e. there is no trailing part, then the *namespace_or_type_name* resolves to `R₀`.
936+
937+
Otherwise each repetition will have one of the forms:
938+
939+
- `.I`
940+
- `.I<A₁, ..., Aₓ>`
941+
942+
where `I`, `A` and `x` are defined as above.
943+
944+
For each repetition `n`, where `1 ≤ n ≤ k`, its resolution, `Rₙ`; which involves `Rₚ`, where `p = n - 1`, the resolution of the preceding repetition; is determined as follows:
945+
946+
- If `x` is zero and `Rₚ` refers to a namespace and `Rₚ` contains a nested namespace with name `I`, then `Rₙ` refers to that nested namespace.
947+
- Otherwise, if `Rₚ` refers to a namespace and `Rₚ` contains an accessible type having name `I` and `x` type parameters, then `Rₙ` refers to that type constructed with the given type arguments.
948+
- Otherwise, if `Rₚ` refers to a (possibly constructed) class or struct type and `Rₚ` or any of its base classes contain a nested accessible type having name `I` and `x` type parameters, then `Rₙ` refers to that type constructed with the given type arguments. If there is more than one such type, the type declared within the more derived type is selected.
949+
> *Note*: If the meaning of `T.I`, for some type `T`, is being determined as part of resolving the base class specification of `T` then the direct base class of `T` is considered to be `object` ([§15.2.4.2](classes.md#15242-base-classes)). *end note*
950+
- Otherwise, the *namespace_or_type_name* is invalid and a compile-time error occurs.
951+
952+
The resolution of the *namespace_or_type_name* is the resolution of the final repetition, `Rₖ`.
925953

926954
A *namespace_or_type_name* is permitted to reference a static class ([§15.2.2.4](classes.md#15224-static-classes)) only if
927955

standard/expressions.md

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3000,9 +3000,12 @@ typeof_expression
30003000
;
30013001
30023002
unbound_type_name
3003-
: identifier generic_dimension_specifier?
3004-
| identifier '::' identifier generic_dimension_specifier?
3005-
| unbound_type_name '.' identifier generic_dimension_specifier?
3003+
: identifier generic_dimension_specifier? ('.' identifier generic_dimension_specifier?)*
3004+
| unbound_qualified_alias_member ('.' identifier generic_dimension_specifier?)*
3005+
;
3006+
3007+
unbound_qualified_alias_member
3008+
: identifier '::' identifier generic_dimension_specifier?
30063009
;
30073010
30083011
generic_dimension_specifier
@@ -3019,13 +3022,19 @@ The first form of *typeof_expression* consists of a `typeof` keyword followed by
30193022

30203023
The second form of *typeof_expression* consists of a `typeof` keyword followed by a parenthesized *unbound_type_name*.
30213024

3022-
> *Note*: An *unbound_type_name* is very similar to a *type_name* ([§7.8](basic-concepts.md#78-namespace-and-type-names)) except that an *unbound_type_name* contains *generic_dimension_specifier*s where a *type_name* contains *type_argument_list*s. *end note*
3025+
> *Note*: The grammars of *unbound_type_name* and *unbound_qualified_alias_member* follow those of *type_name* ([§7.8](basic-concepts.md#78-namespace-and-type-names)) and *qualified_alias_member* ([§14.8.1](namespaces.md#1481-general)) except that *generic_dimension_specifier*s are substituted for *type_argument_list*s. *end note*
3026+
3027+
When recognising the operand of a *typeof_expression* if both *unbound_type_name* and *type_name* are applicable, namely when it contains neither a *generic_dimension_specifier* nor a *type_argument_list*, then *type_name* shall be chosen.
3028+
3029+
> *Note*: ANTLR makes the specified choice automatically due to the ordering of the alternatives of *typeof_expression*. *end note*
3030+
3031+
The meaning of an *unbound_type_name* is determined as if:
30233032

3024-
When the operand of a *typeof_expression* is a sequence of tokens that satisfies the grammars of both *unbound_type_name* and *type_name*, namely when it contains neither a *generic_dimension_specifier* nor a *type_argument_list*, the sequence of tokens is considered to be a *type_name*. The meaning of an *unbound_type_name* is determined as follows:
3033+
- The sequence of tokens is converted to a *type_name* by replacing each *generic_dimension_specifier* with a *type_argument_list* having the same number of commas and the keyword `object` as each *type_argument*.
3034+
- The resulting *type_name* is resolved to a constructed type ([§7.8](basic-concepts.md#78-namespace-and-type-names)).
3035+
- The *unbound_type_name* is then the unbound generic type associated with the resolved constructed type ([§8.4](types.md#84-constructed-types)).
30253036

3026-
- Convert the sequence of tokens to a *type_name* by replacing each *generic_dimension_specifier* with a *type_argument_list* having the same number of commas and the keyword `object` as each *type_argument*.
3027-
- Evaluate the resulting *type_name*, while ignoring all type parameter constraints.
3028-
- The *unbound_type_name* resolves to the unbound generic type associated with the resulting constructed type ([§8.4](types.md#84-constructed-types)).
3037+
> *Note*: There is no requirement for an implementation to transform the sequence of tokens, or produce the intermediary constructed type, just that the unbound generic type that is determined is “as if” this process was followed. *end note*
30293038
30303039
It is an error for the type name to be a nullable reference type.
30313040

0 commit comments

Comments
 (0)