dotnet/roslyn

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

Open

#369 geöffnet am 10. Feb. 2015

Auf GitHub ansehen
 (3 Kommentare) (0 Reaktionen) (0 zugewiesene Personen)C# (4.257 Forks)batch import
Area-CompilersBugLanguage-C#Pedantic ;)help wanted

Repository-Metriken

Stars
 (20.414 Stars)
PR-Merge-Metriken
 (Durchschn. Merge 6T 17h) (256 gemergte PRs in 30 T)

Beschreibung

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