Skip to content

File-local type doesn't "shadow" namespaces #68429

@RikkiGibson

Description

@RikkiGibson
// File1.cs
namespace App.Widget
{
    class Inner { }
}

// File2.cs
namespace App
{
    file class Widget { } // unexpected error: The namespace 'App' already contains a definition for 'Widget' in this file.
}

Specification should be updated. We should not get an error here, and usages of App.Widget in File2.cs should refer to file class App.Widget, not to namespace App.Widget.

Lookup

We amend the member lookup section as follows (new text in bold):

  • 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 (§11.6.3) might be able to infer the type arguments.
  • Next, let F be the compilation unit which contains the expression where member lookup is occurring. All members which 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 non-file-local types are removed from the set.

Metadata

Metadata

Assignees

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions