-
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
No nullable warning issued for null event invocation #34982
Comments
Why would this warn? The event (and the backing field) are both non-nullable. Is the suggestion that the backing field be annotated as nullable if nullability is enabled? |
There are two possible warnings here. Either:
It's currently doing neither of those. And it's super rare to initialize an event in a constructor, as 99.9% of the time events are meant to start life without any registrations. So I think declaring an event should map to the latter case, creating the equivalent of a nullable backing field. But if for some reason we don't want to do that, as noted, this sample should still warn about something. |
Good point about the lack of warning on initialization. Events seem like an odd case to me. As you mentioned the field, by default, is So I agree, I think even with nullability enabled and the event accessors marked as non-nullable the backing field should still be nullable. I think that would do the most good. |
should nullability only affect |
We've not implemented nullability analysis of events yet. |
Closing, as the compiler now treats events like fields, and so warns if you've not made the event nullable or initialized it to non-null, and if you make it nullable, then you get invocation warnings. |
Version Used:
3.1.0-beta1-19172-05+edd2de88fb3e84a097fb30b4070e0f219f624e40
Steps to Reproduce:
No warning is issued here, but it will null ref.
cc: @dotnet/nullablefc
The text was updated successfully, but these errors were encountered: