Use ThrowHelper to throw exceptions (part 1)#4872
Conversation
|
Just as info: with .NET 8 alot of throw-helpers come inbox (ArgumentOutOfRange, ObjectDisposed, etc.). |
|
Maybe we should already add the net8.0 TFM and make this a shim. |
|
I'm marking the PR as ready for review. There are going to be multiple parts to make it easire to review. Adding .NET 8 TFM and referencing inbox throw-helpers should probably be done in a separate pr. One interesting thing I've encountered while working on this PR is that jit generates a lot of code for string interpolation even if the argument is a constant (though |
Interesting... The nameof case shows that it does the right thing for at least some constants, but for fails with ushort.MaxValue... Maybe because it's a non-string and so requires a conversion, and Roslyn doesn't do that? I'd flag this on https://github.com/dotnet/roslyn (assuming there's not already an issue) Aside from that there are some test failures... |
Some issue with downloading PG, gonna restart... |
For codegen look at what Roslyn generated. For strings in interpolation holes C# 10 has the feature of "constant interpolated strings". |
It seems like integers (and I guess that includes uint) aren't a constant interpolated string because of a formatting differences across cultures? |
Ah yeah, that makes sense. Though if memory serves, there's a way to specify invariant culture inside the interpolation, and that could be done at compile-time. |
roji
left a comment
There was a problem hiding this comment.
Am fine with this, though I wonder if it's worth systematically doing this for the entire codebase... In other words, there are methods which are never going to get inlined anyway (because they're big), and so doing this there doesn't seem to have much value; in some places it also makes code readability worse (because we can't throw from expression context).
Yeah, I'm definitely not going to remove them from everywhere any time soon) |
Contributes to #2237
Draft until I check the code jit compiles.