dotnet/roslyn

diagnostic for override in Interface should suggest using explicit interface implementation instead

開放

#39,940 建立於 2019年11月21日

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

倉庫指標

星標
 (20,414 顆星)
PR 合併指標
 (平均合併 6天 17小時) (30 天內合併 256 個 PR)

描述

Version Used: VS 16.4 preview 4

Steps to Reproduce:

The following code fails to compile:

public interface I {
    abstract void M();
}

public interface I1 : I {
    override void M() {}
}

public class C : I1 {}

The correct code should be:

public interface I {
    abstract void M();
}

public interface I1 : I {
    void I.M() {}
}

public class C : I1 {}

However it's not immediately obvious that's the case, and there's nothing pointing you to use explicit interface implementation instead.

Expected Behavior:

DIagnostic should be:

error CS0106: The modifier 'override' is not valid for this item. Use explicit interface implementation void I.M instead.

Ideally there should also be a code fix for this.

Actual Behavior:

error CS0106: The modifier 'override' is not valid for this item

貢獻者指南