Area-CompilersConcept-Diagnostic Clarityhelp wanted
仓库指标
- 星标
- (20,414 个星标)
- PR 合并指标
- (平均合并 6天 17小时) (30 天内合并 256 个 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.