Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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
Updating generic math to support user-defined checked operators #67714
Updating generic math to support user-defined checked operators #67714
Changes from 4 commits
9ccdb26
b974238
ea8bf0c
ea27d1c
518a446
910d974
80b166b
File filter
Filter by extension
Conversations
Jump to
There are no files selected for viewing
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 is interesting. DateTime.MaxValue + TimeSpan.FromMilliseconds(1) will throw an exception, regardless of checked. In a generic math context, that feels a little strange, but I'm not sure there's a better answer (as long as we continue to want these only-slightly-math-related types implementing these interfaces).
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.
I think this is an area where we'll want to consider the implications of there now being
user-defined checked operators
for certain core types (likeDateTime
and similar).One could imagine us "properly" supporting checked/unchecked contexts for these types now. One could also imagine us continuing to always throw on overflow.
checked(expr)
doesn't necessarily mean thatexpr
will throw on overflow; andunchecked(expr)
doesn't necessarily mean thatexpr
will not throw on overflow. It really depends on the type and what operations it decides to support.We'll probably want to decide on guidance as well, including the implications of taking the behavioral break for already compiled dependents.
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.
We also have the option of saying:
DateTime
always overflows when used as a concrete type but when used in a generic math context it properly respectschecked
/unchecked
. We can always have the public APIs and the explicit interface implementations SxS, just needing to have API review in agreement that's overall good/desirableThere 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.
Right. Seems like we basically have four options:
We don't need to decide now, but please ensure there's an issue open to track making a decision around this for .NET 7.
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.
Will log an issue tracking this before merging.
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.
#67744