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
Detect wrong argument constraint type at runtime #1237
Comments
I like the idea of simply rejecting all expressions that are conversions in @thomaslevesque may be right: we might need to investigate the types that we get from the constraint trap. |
From #1230:
As you like @blairconrad. I'm mostly done, but I haven't written any tests yet, and I won't have time to work on it for a few days. If you want to look at what I have, here it is: thomaslevesque@41e6011 I added a new |
Oh, man. My approach was going to be totally different. Which probably means I'm forgetting lots of stuff! I don't mind just noodling along as a hobby even if/when we take your fix. I'm going to be away tomorrow and then Friday through Sunday as well, so who knows when I'll be done… |
I look forward to seeing what you had in mind ;) |
Well, here it is. Very rough. Tests at least need review and the production code needs refactor. |
It's an interesting approach. I like the fact that it doesn't require as much changes as mine. On the other hand, it doesn't detect wrong types in hidden nested constraints, e.g. constraints created by user-defined methods. |
Can you gimme an example of such a thing? |
Something like this:
Or even:
|
Ugh. You're right, of course. I need to look at your solution more closely to see how it works. I have to relearn argument constraint trapping every single time I look at it. |
You don't really need to understand it... I didn't touch how constraints are trapped, I'm just examining the results. |
I found my refresher to be useful anyhow. Your approach has more promise. Abandoning mine. |
This change has been released as part of FakeItEasy 4.2.0. |
Related to #1177, #1230, #1163
We already have the FakeItEasy0005 diagnostic to detect this, but we can also detect it at runtime, and we should throw in this case.
A possible approach would be to examine all the constraints collected by
IArgumentConstraintTrapper.TrapConstraints
and check if their type is compatible with the parameter type.The text was updated successfully, but these errors were encountered: