fix: Add null checks when mapping nullable sources to non-nullable targets with MayBeNull and AllowNull Attribute#2256
Conversation
|
Thanks for the contribution! The fix turns out to be a bit more involved than it might initially appear, IMO also my original |
|
Thanks, that makes sense! I checked and it looks like AllowNull isn't currently considered in target nullability checks (I also couldn’t find any tests covering it). Would you prefer this to be handled in a separate PR focusing on AllowNull support? Also, regarding the implementation: would you recommend modeling read and write nullability as separate properties (e.g., sourceMayBeNull vs targetAcceptsNull), or passing a context flag like isRead/isWrite? |
|
As these two strongly belong together and the changes shouldn't get too big, I'd do it in the same PR. |
latonz
left a comment
There was a problem hiding this comment.
Thanks for the updates, I added my feedback.
Please also update the 5-0.md breaking changes docs.
|
@latonz Thanks for the review. I realized I forgot to mark the PR as a draft earlier. Your feedback was really helpful. |
|
@latonz |
latonz
left a comment
There was a problem hiding this comment.
Thanks for the updates. One small feedback point left.
Could you please also rebase? Afterwards I'll merge it 😊
todo - add test for allow Null
737c17d to
c37630f
Compare
I have updated the PR and rebased the branch. |
|
@Abhijithtv thank you for this contribution |
Add null checks when mapping nullable sources to non-nullable targets with MayBeNull Attribute
Description
For target members, [MaybeNull] should not be considered when determining nullability.
Otherwise, it may lead to incorrect nullable analysis and result in CS8601 ("Possible null reference assignment") warnings.
Fixes #2192
Checklist