-
Notifications
You must be signed in to change notification settings - Fork 4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Pulling up an event to an interface should not add/reproduce the nullable annotation #40292
Comments
I don't know why the annotation would be dropped here. All events are expected to support adding/removing null delegates, and upon implementing the interface, having the type be non-nullable will lead to warnings (and then if they're suppressed, likely false negatives upon invocation of the event). |
This is a bit of an interesting case in that i don't think a user externally could ever observe the nullability of these events. i.e. when accessing through the interface, you can't ever refer to the 'Action' value itself (in order to observe it's null/non-null-ness). All you can do is ever do So i would ask:
Is this the case? I don't get any warnings with this @stephentoub 👍 class Program
{
public void DoWork(ITest i)
{
Action? e = null;
i.E += e;
}
}
public interface ITest
{
event Action E;
} @jcouv for thoughts. I'm not sure how much of NRT+events is intentional, or just where we've landed today unintentionally. |
It's supposed to be. |
Hrm.. we may want to reconsider that. Esp. since we've now shipped with thsi behavior and likely could not change it. i.e. it seems like we do respect this:
We can't now null check these and introduce new warnigns (esp. on code which seems like it should be totally correct and would not throw). I guess we should take this to LDM to see waht to do here. @jcouv do you want to drive? |
Shipped when? We've made plenty of changes for .NET 5 that introduce new nullable warnings. That was part of the deal for rolling out nullable reference types. |
If it's declared to be non-nullable, throwing is perfectly valid behavior if null is passed in. Such non-nullability is simply considered bad form for events. |
We currently do very little nullability analysis of events (known gap). It's still possible to fix some of those for .NET 5. |
Closing out due to lack of feedback here. |
Version Used:
16.4.1
Steps to Reproduce:
Expected Behavior:
public interface ITest { + event Action E; }
Actual Behavior:
public interface ITest { + event Action? E; }
The text was updated successfully, but these errors were encountered: