dotnet/roslyn
Bad diagnostic when interface override has wrong return type.
Offen
#43.719 geöffnet am 27.04.2020
Area-CompilersConcept-Diagnostic Clarityhelp wanted
Repository-Metriken
- Stars
- (20.414 Sterne)
- PR-Merge-Metriken
- (Durchschn. Merge 6T 17h) (256 gemergte PRs in 30 T)
Beschreibung
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.