ulrichb / ImplicitNullability

Extends ReSharper's static nullability analysis by changing specific, configurable elements to be [NotNull] by default
MIT License
44 stars 7 forks source link

ImplicitNotNullConflictInHierarchy requires code duplication #1

Closed kwesolowski closed 8 years ago

kwesolowski commented 9 years ago

It is assumed already by ReSharper that when interface/abstract/overriden method has [NotNull]/[CanBeNull] annotations then inheriting types should conform (and repeating attribute is grayed out as redundant).

So am I missing something or I should just disable this inspection?

ulrichb commented 9 years ago

@kwesolowski: You are right, ReSharper's "Base declaration has the same annotation" redundant code warning competes with Implicit Nullability's "Implicit NotNull conflicts with nullability in super type".

There are two reasons why in the projects where we use Implicit Nullability we ignore ReSharper's "Base declaration has the same annotation" warning (and changed its severity level to "Hint").

  1. We use Fody NullGuard, which doesn't have the "annotation inheritance" as ReSharper's static analysis has built in, and therefore needs duplicating [CanBeNull] annotations in method overrides (otherwise it would inject null checks although the base method is decorated with [CanBeNull]).
  2. As documentation in method overrides. The nullability of reference types can also be seen as part of the type itself (which is the case in other programming languages and for value types also in C#). Then, it seems natural to have the [CanBeNull] information also in the derived types.

Of course, if both points do not apply, you can change the "Implicit NotNull conflicts with nullability in super type" warning's severity to "Hint", or "Do not show".

ulrichb commented 8 years ago

As a new feature in version 3.0.0, Implicit Nullability now filters ReSharper's AnnotationRedundancyInHierarchy ("Base declaration has the same annotation") highlighting specifically for code elements with enabled implicit nullability. So you can enable the inspection again (to get it for code elements without enabled implicit nullability).