-
Notifications
You must be signed in to change notification settings - Fork 414
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
Replace null-forgiving operator uses with debug assertions #890
Conversation
Codecov Report
@@ Coverage Diff @@
## master #890 +/- ##
==========================================
- Coverage 92.53% 92.38% -0.15%
==========================================
Files 108 110 +2
Lines 3428 3441 +13
Branches 1020 1020
==========================================
+ Hits 3172 3179 +7
- Misses 194 200 +6
Partials 62 62
📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more |
While I am not opposed to Example use case: var g = Debug.AssertNotNull(_lastGrouping); |
You can't do that because such assertion methods are conditional methods that get compiled out of release builds and therefore they must return
|
Ah, I missed the |
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.
Approved for now. I have specific recommendations for different improvements for several of these, but those can be done later.
I've added this idea with 7e6fa33 and updated the initial description with:
|
Finished product LGTM |
This adds to commit b31c7fd, "Replace null-forgiving operator uses with debug assertions (morelinq#890)".
This PR introduces
Debug.Assert
that's defined similarly toSystem.Diagnostics.Debug.Assert
to help eliminate the bulk uses of the null-forgiving operator (!
). The assertion more explicitly states the illegal case, and if triggered, will also relay the offending condition in the message. It also eliminates needing to suppress CS8602 and CS8603 in targets earlier than .NET 6.This PR also adds
Assume.NotNull
, that's aDebug.Assert
in disguise, but which specifically asserts the not-null-reference case. The idea is to make these cases easily searchable in code.