dotnet/roslyn

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

Open

#369 建立於 2015年2月10日

在 GitHub 查看
 (3 留言) (0 反應) (0 負責人)C# (20,414 star) (4,257 fork)batch import
Area-CompilersBugLanguage-C#Pedantic ;)help wanted

描述

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]

貢獻者指南