dotnet / dotnet/csharpstandard
namespace_or_type_name is not permitted to reference a static class in a using_directive
- Dominant language
- C#
- Stars
- 815
- Forks
- 99
- Avg merge
- 1d 14h
- Merged PRs (30d)
- 16
Description
**Describe the bug**
[C# 7 subclause 7.8.1](https://github.com/dotnet/csharpstandard/blob/standard-v7/standard/basic-concepts.md#781-general) does not permit a *namespace_or_type_name* to reference a static class when it is in a *using_alias_directive* ([14.5.2](https://github.com/dotnet/csharpstandard/blob/standard-v7/standard/namespaces.md#1452-using-alias-directives)) or a *using_static_directive* ([14.5.4](https://github.com/dotnet/csharpstandard/blob/standard-v7/standard/namespaces.md#1454-using-static-directives)). Those uses are not part of [this list in 7.8.1](https://github.com/dotnet/csharpstandard/blob/02d1a90122ece425cff575f47f197fb396be73d4/standard/basic-concepts.md?plain=1#L896-L899):
> A *namespace_or_type_name* is permitted to reference a static class ([§15.2.2.4](https://github.com/dotnet/csharpstandard/blob/standard-v7/standard/classes.md#15224-static-classes)) only if
>
> * The *namespace_or_type_name* is the `T` in a *namespace_or_type_name* of the form `T.I`, or
> * The *namespace_or_type_name* is the `T` in a *typeof_expression* ([§12.8.17](https://github.com/dotnet/csharpstandard/blob/standard-v7/standard/expressions.md#12817-the-typeof-operator)) of the form `typeof(T)`
**Example**
This is allowed by 14.5.2 and 14.5.4 but not by 7.8.1.
```csharp
using A = N.S;
using static N.S;
namespace N
{
static class S
{
}
}
```
**Expected behavior**
7.8.1 should allow a *namespace_or_type_name* to reference a static class in these additional cases:
* The *namespace_or_type_name* is in a *using_alias_directive* (14.5.2).
* The *namespace_or_type_name* is the *type_name* in a *using_static_directive* (14.5.4).
**Additional context**
14.5.2 references *namespace_or_type_name* in the definition of *using_alias_directive*:
14.5.4 references *type_name* in the definition of *using_static_directive*:
7.8.1 explains that a *type_name* is a *namespace_or_type_name*:
Inspired by .
Contributor guide
Assessment
This issue has not been assessed yet.