dotnet/roslyn

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

Open

#369 aperta il 10 feb 2015

Vedi su GitHub
 (3 commenti) (0 reazioni) (0 assegnatari)C# (4257 fork)batch import
Area-CompilersBugLanguage-C#Pedantic ;)help wanted

Metriche repository

Star
 (20.414 star)
Metriche merge PR
 (Merge medio 6g 17h) (256 PR mergiate in 30 g)

Descrizione

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]

Guida contributor