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
Ignored/That argument constraints do not Work for ByRef-Arguments in VisualBasic #899
Comments
Hi @thunderbird55, Interesting... we never noticed this issue before, because it can't occur in C#. In C#, only a local variable or a field can be passed by reference, not a value (like I'll look into it. In the meantime, for this specific case you can use this:
If there are other arguments that need to be constrained, you can use |
Hi @thomaslevesque
becomes
|
Yes, but that doesn't really explain the error message... I'll need to debug step by step to see exactly why it's not working. |
@thomaslevesque, I think @thunderbird55 has explained the error message. A corollary to yo's last statement is that A.CallTo(Sub() test.BarByRef(A(Of Object).Ignored)).MustHaveHappened() becomes Dim tmp As Object = A(Of Object).Ignored
A.CallTo(Sub() test.BarByRef(tmp)).MustHaveHappened() And the latter will throw on the first line. |
Ah, yes, I missed that. Actually, I expected the code to become something like this:
(probably not valid syntax, but you get what I mean) But it doesn't really change anything, since So, in fact, I'm not sure if this should be considered a bug. We can't use argument constraint on by-ref parameters:
What bothers me is that the error message is really confusing, and I'm not sure what we could do to improve it... |
btw @thunderbird55, maybe this code didn't throw in FakeItEasy 1.x, but it didn't do what you would expect either: Starting in 2.0.0, we made |
@thomaslevesque A.CallTo(
Sub() attHandler.ElementStart(A(Of String).Ignored,
A(Of CAttributes).That.Matches(Function(pAtt) pAtt.Value("Nr") = "200"))
).MustHaveHappened() And this code worked with version 1.23 And I think your expectation is right, I forgot that this was inside a lambda. But honestly I'm not sure what VB does inside lamda statements. |
I renamed this to make the title a little more accurate (as I understand things). And labelled it as a discussion so we don't lose it. Also, I'm a little confused. Based on my understanding of how |
I think we should close this issue as |
At the very least, I'd update the docs, explaining the shortcoming for the VB users. |
Late-breaking news! The cause of the problem isn't what we thought it was. And it's a bug. The fixes for #220 and #559 conspired together to cause it. When we try to get the value to implicitly assign to the ref parameter, we end up invoking |
Isn't it what we were saying the cause was? |
OK, I see what you mean now. The problem seems to be here: https://github.com/FakeItEasy/FakeItEasy/blob/master/src/FakeItEasy/Expressions/ExpressionArgumentConstraintFactory.cs#L39 I have a fix ready, I'll send a PR ASAP |
We could also consider backporting to the 2.x branch. |
I don't mind backporting the fix to 2.x, it's not a big deal. |
It is a nice gesture. If I thought 3.0 were coming out real soon, I'd say skip it. But if you're game, I'll happily do the review/merge. Thanks! |
Oh, if you do decide to port to 2.3.2, beware of #515. |
I'll take care of it tomorrow if I can. For now I just created the support-2 branch and cherry-picked the fix. |
Merged and made release, milestone, release issue, PR to set version. I think we are in good shape. |
Thanks! |
Thank you very much. |
All Versions >= 2.00
See the following interface
As soon as I want to use any argument constraint for an ByRef-Argument an exception is thrown. (System.InvalidOperationException: A.Ignored, A._, and A.That can only be used in the context of a call specification with A.CallTo)
The text was updated successfully, but these errors were encountered: