DotNetAnalyzers / StyleCopAnalyzers

An implementation of StyleCop rules using the .NET Compiler Platform
MIT License
2.64k stars 506 forks source link

Explicit interface implementation triggers access level error #3881

Open marcospgp opened 1 month ago

marcospgp commented 1 month ago

Ran into this today using stylecop.analyzers.1.1.118:

image

bjornhellander commented 1 month ago

And why do you think this is a bug? https://github.com/DotNetAnalyzers/StyleCopAnalyzers/issues/1179#issuecomment-2265942033

sharwell commented 4 weeks ago

It's not quite clear what the issue being reported is (primarily because SA1202 involves the relation between two different members, but only one member is shown). Explicit interface implementations were treated as public by StyleCop Classic. StyleCop Analyzers intentionally preserved this behavior.

During the creation of this project, the default behavior was always to follow StyleCop Classic (for ease of migration for existing users) unless a change was warranted. If the intended behavior was unclear due to ambiguity or omissions in the old documentation, our preference was to preserve the implementation behavior and clarify the documentation. We tried to only change behavior in cases where rules were found to be in direct conflict with each other, or were largely/fundamentally incompatible with explicit guidance being given by the language team. In those cases, we tried to document the differences in Known Changes.

marcospgp commented 3 weeks ago

since interfaces can only define public abstract methods, it makes sense to assume an explicit interface implementation will always be public - even if it is only accessible by casting an instance to the interface type

is there any chance the error message could be updated to include this information? or as a fallback, the documentation?