-
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
Are nullable annotations on events meaningful/allowed? #29839
Comments
What if for an automatic/field-like event, the backing field is implicitly considered nullable? Essentially: public event EventHandler OnFoo; //Compiler generates: private EventHandler? m_OnFoo;
private void Foo()
{
//....
OnFoo(this, EventArgs.Empty); //warning: event could NRE if there are no subscribers
} A special fix would be suggested to use null-safe invocation: |
Closing. Events can be set to using System;
public class C {
event Action E;
public void M()
{
E = null;
E();
}
} |
If we allow annotations for events:
It feels like it is very common for an event to not have any subscribers. It would also be good to get clarity on what do we consider a safety issue around an event? An invocation of a field-like event that might have no subscribers? Something else. |
I added some references to this issue in the code. In particular, if nullability is meaningful for events, we'll also want to honor annotations ( |
@jcouv I see this is marked as "archived" in the project board -- it is still being tracked? |
@jasonmalinowski I don't see this issue marked as "archived": |
@jcouv That's the little icon before the word "event". I had no idea that was a feature until seeing it just now. |
@jasonmalinowski Indeed. Not sure what happened. Restored it now. Thanks! |
Tagging @agocke I'm pushing this whole bucket (nullability analysis of events) post C# 8 RTM |
This was discussed in LDM today (7/17/2019) with the conclusion that |
@AlekseyTs is this issue still relevant? |
This issues is created for a
that was in AnnotationWithoutNonNullTypes unit-test.
The text was updated successfully, but these errors were encountered: