dotnet/roslyn

Unexpected error CS0146: "Circular base class dependency involving 'A.B' and 'A.B'" in using static directive

Open

#369 opened on Feb 10, 2015

View on GitHub
 (3 comments) (0 reactions) (0 assignees)C# (20,414 stars) (4,257 forks)batch import
Area-CompilersBugLanguage-C#Pedantic ;)help wanted

Description

using static A.B.B;

class A
{
    public class B : A { }
}

ACTUAL: SourceCode.cs(1,18): error CS0146: Circular base class dependency involving 'A.B' and 'A.B'

EXPECTED: No errors

The problem seems to be in the Microsoft.CodeAnalysis.CSharp.InContainerBinder.LookupSymbolsInSingleBinder method (%Roslyn%\src\Compilers\CSharp\Portable\Binder\InContainerBinder.cs, around line 151).

It looks like there is no inherent circularity there, but it arises because of the particular order of method calls in our implementation. We unconditionally call GetImports first to completely bind all using directives, but this is not actually necessary if we find the declaration of the required symbol directly in the corresponding namespace declaration, we only need to check the names of aliases introduced in using alias directives for potential conflicts (we do not even need to bind the symbols they refer to), and we should not care at all about using namespace or using static directives in this case.

[Migrated from TFS DevDiv 1108103]

Contributor guide