dotnet / dotnet/csharpstandard

Spec: Does not describe member lookup for using static

Open
#307 3 comments 0 reactions 0 assignees View on GitHub
Dominant language
C#
Stars
815
Forks
99
Avg merge
1d 14h
Merged PRs (30d)
16

Description

The C# 6.0 draft specification section on [member lookup](https://docs.microsoft.com/en-us/dotnet/csharp/language-reference/language-specification/expressions#member-lookup) does not discuss the rules for member lookup in the presence of `using static` directives. Neither does the section on [using static](https://docs.microsoft.com/en-us/dotnet/csharp/language-reference/language-specification/namespaces#using-static-directives).

For example, I do not believe the spec defines what will happen in the following program:

```csharp
using System;
using static A;
using static B;

Console.Write(C.M(X));

public class A
{
public static void X(){}
}

public class B
{
public static bool X;
}

class C
{
public static string M(Action a) => "action";
public static string M(bool b) => "bool";
}
```

In practice it prints "action".

The spec should be updated to reflect this.

The relevant part of the spec is this line I think:

> If M is a method, then all non-method members declared in a base type of S are removed from the set.

Maybe this should be updated to:

> If M is a method, then all non-method members are removed from the set.

But I am not sure.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.