Replies: 4 comments 5 replies
-
This is by design, see section https://github.com/dotnet/csharplang/blob/main/proposals/csharp-8.0/default-interface-methods.md#overrides-in-interfaces: "members that are not
Adding an abstract API to an existing interface has always been a breaking change. I really do not see non-public accessibility making it any worse than it always was. |
Beta Was this translation helpful? Give feedback.
-
This does seem like an issue for me. Tagging @MadsTorgersen . The error is particularly strange:
First, ComplexCollection does implement htat interface member. It does definitionally as this is a DIM, so the implementation is already there. Second: "ComplexCollection.Count()' cannot implicitly implement a non-public member." Why are we error'ing there? Why are we trying to implicitly impl a non-public DIM member in the first place? |
Beta Was this translation helpful? Give feedback.
-
Thank you for clarifications. If I remember correctly, the motivation behind the error is to guard a user against falling into the muscle memory "trap" by using an implicit implementation to implement non-public APIs. This is not just about protected, but about any non-public APIs. The error is reported because it looks like the intent might be to actually implement the API rather than rely on possible default implementation or implementation from a base class. The error is reported only when the signature fully match, etc. I.e. only when accessibility is the only reason to "ignore" the API as an implementation. Certainly, this behavior can cause some inconvenience as you demonstrated. It might be worth considering removal of the error, since DIM feature is no longer new. |
Beta Was this translation helpful? Give feedback.
-
I think this situation is related and I find the result extremely confusing. public interface IFoo
{
public string Bar { get; internal set; }
}
public class Foo : IFoo
{
public string Bar { get; internal set; } //Error - Non-public accessor "Bar.set" cannot implement accessor from interface IFoo
} Why is this code invalid? And even if there is a good reason, the error given is not very good. |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
I posted last year the following issue dotnet/roslyn#43680
With the following content:
Protected interface members seem to prohibit members in implementing types with the same name and non explicit interface implementations.
Consider the following code:
If you compile it with roslyn you get error "CS8704", which says you can't override / implement the protected interface member implicitly. If you want to do this it must be done explicit.
I think this should be just a warning or completely removed. If you extend an interface with such protected methods you may break existing code.
In the spec I couldn't find a reason why this situation should cause an error.
This situation makes the usage of protected interface members very difficult. Is this a roslyn bug or is it intended?
Beta Was this translation helpful? Give feedback.
All reactions