-
-
Notifications
You must be signed in to change notification settings - Fork 802
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
Improve error message when verification fails #1138
Comments
Your contribution would be welcome @bfriesen! I haven't yet had time to study your code in detail, but I expect that some further simplifications would be possible. To give you a few pointers:
Do you think you can simplify your code further using these hints? I'll do an in-depth code review on your PR (if you choose to submit one).
I'd probably go with "changed" and provide a high-level description like "improved error message formatting of ...". |
I saw that extension method, but I don't think it's relevant here, since I'm trying to omit the name of the closure type, not format it better.
This looks similar to what I'm trying to accomplish. I'll look into this in greater detail later tonight/tomorrow and see if it could simplify my changes.
I don't think this is relevant either, since the captured local variables appear as instance fields of the compiler-generated closure class. |
I think actually using |
Great work! Thanks for your contribution! |
P.S.:
I agree that the former check is nicer and means we won't need to implement a parser for those generated names. 🙂 And that particular check has worked well in practice, so far. That being said, here's some trivia you may find of interest: While the former check may look nicer, the latter is potentially more accurate. As you may know, those horrible-looking generated names actually have a specific format (see this comment in the Roslyn compiler source) and the On the other hand, |
I would like to improve the verification error message for these two specific scenarios:
Currently, if you have a variable of type
LambdaExpression
, and you pass it in to theIt.Is<TValue>
static method, and verification fails, then the formatting of the lambda expression in the exception message isn't as good as it should be. Specifically, the representation of the lambda expression in the message is poor becauseToString()
has been called on it instead of the friendly expression formatting routine.The second assertion fails with the message (nobody wants to see "<>c__DisplayClass" - yuck!):
Note the lambda expression
s => IsNullOrEmpty(s)
, when it should bes => string.IsNullOrEmpty(s)
. There seems to be a difference in how a lambda expression is constructed depending on whether it is captured in a variable or not. When captured in a variable, the overall expression contain aConstantExpression
which has a value of type LambdaExpression - this is the actual lambda expression that we want. However, currently, the value of all constant expressions is basically formatted by callingToString()
on them.Assuming scenario 1 (where we have a variable of type lambda expression passed to
It.Is
), if a lambda expression captures a local variable as a closure, then we should not include the ugly name of the closure class (beginning with "<>c__DisplayClass") in the verification failed message.The second assertion fails with the message (nobody wants to see "<>c__DisplayClass" - yuck!):
I have a branch containing these tests, along with a fix for each. If this is something you're interested in, I'll make a pull request. I do have one question though: for the purpose of the updating the changelog, is this an 'Added', 'Changed' or 'Fixed'?
The text was updated successfully, but these errors were encountered: