dotnet/roslyn

Bad diagnostic when interface override has wrong return type.

已關閉

#43,719 建立於 2020年4月27日

 (0 則留言) (0 個反應) (0 位負責人)C# (4,257 個分叉)batch import
Area-CompilersConcept-Diagnostic Clarityhelp wanted

倉庫指標

星標
 (20,414 顆星)
PR 合併指標
 (PR 指標待抓取)

描述

The following test demonstrates that the diagnostic given for an incorrect return type in an interface implementation doesn't make sense.

        [Fact]
        public void TEMP()
        {
            var source = @"
public interface Base
{
    public virtual object M1 => null;
    public virtual object M2() => null;
}
public interface Derived : Base
{
    string Base.M1 => null;
    string Base.M2() => null;
}
public class C : Base
{
    string Base.M1 => null;
    string Base.M2() => null;
}
";
            CreateCompilation(source, targetFramework: TargetFramework.NetStandardLatest).VerifyDiagnostics(
                // (9,17): error CS0539: 'Derived.M1' in explicit interface declaration is not found among members of the interface that can be implemented
                //     string Base.M1 => null;
                Diagnostic(ErrorCode.ERR_InterfaceMemberNotFound, "M1").WithArguments("Derived.M1").WithLocation(9, 17),
                // (10,17): error CS0539: 'Derived.M2()' in explicit interface declaration is not found among members of the interface that can be implemented
                //     string Base.M2() => null;
                Diagnostic(ErrorCode.ERR_InterfaceMemberNotFound, "M2").WithArguments("Derived.M2()").WithLocation(10, 17),
                // (14,17): error CS0539: 'C.M1' in explicit interface declaration is not found among members of the interface that can be implemented
                //     string Base.M1 => null;
                Diagnostic(ErrorCode.ERR_InterfaceMemberNotFound, "M1").WithArguments("C.M1").WithLocation(14, 17),
                // (15,17): error CS0539: 'C.M2()' in explicit interface declaration is not found among members of the interface that can be implemented
                //     string Base.M2() => null;
                Diagnostic(ErrorCode.ERR_InterfaceMemberNotFound, "M2").WithArguments("C.M2()").WithLocation(15, 17)
                );
        }

These diagnostics don't make sense because, among other reasons, the quoted thing they say is not found (e.g. 'Derived.M1' in the first diagnostic) is not something that appears anywhere in the program.

貢獻者指南