-
Notifications
You must be signed in to change notification settings - Fork 1k
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
Enable nullability in ArrayEditor #12675
base: main
Are you sure you want to change the base?
Conversation
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #12675 +/- ##
===================================================
- Coverage 76.08157% 76.07980% -0.00177%
===================================================
Files 3257 3257
Lines 642145 642089 -56
Branches 47286 47286
===================================================
- Hits 488554 488500 -54
- Misses 150041 150045 +4
+ Partials 3550 3544 -6
Flags with carried forward coverage won't be shown. Click here to find out more. |
@@ -22,12 +20,12 @@ public ArrayEditor(Type type) : base(type) | |||
/// Gets or sets the data type this collection contains. | |||
/// </summary> | |||
protected override Type CreateCollectionItemType() | |||
=> CollectionType?.GetElementType(); | |||
=> CollectionType?.GetElementType()!; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please add a comment, explaining in detail why CollectionType?.GetElement()!
will never return null.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This can actually be null, but changing it seems to require changing the base class which does not return null.
@lonitra should I change the base class? Alternatively, I could return string.Empty here instead, but this would mean a breaking change.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The base class does not guarantee that CollectionType is not null, it should throw in the constructor when a null is passed in. Once we throw this exception, we can get rid of the question mark -
protected override Type CreateCollectionItemType() => CollectionType.GetElementType()!;
And for GetElementType returning null, I would throw InvalidOprationException, it could happen only if this type is not an array
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Tanya-Solyanik I added a separate commit with the proposed changes, but this affects lots of tests. Are we sure that we want to apply this change? If yes, I will update the tests. If not, any other suggestions?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, please update the tests.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Copilot reviewed 1 out of 2 changed files in this pull request and generated no comments.
Files not reviewed (1)
- src/System.Windows.Forms.Design/src/PublicAPI.Shipped.txt: Language not supported
4146557
to
fe38e2a
Compare
Proposed changes
Microsoft Reviewers: Open in CodeFlow