Comments (3)
@drivehappy Thank you for your very detailed problem report and steps to reproduce this problem. I took a closer look at the problem myself and was able to isolate it @ptrelford. It is caused by loading a return variable of type void
and issuing multiple Ret
statements (both problems are directly related). The given code causes the following statements to be emitted (for foo
):
...
// Part1
OpCodes.Ldarg_0
OpCodes.Ldfld, returnValuesField
OpCodes.Ldc_I4, returnValuesIndex
OpCodes.Ldelem_Ref
OpCodes.Unbox_Any, returnType
OpCodes.Ret
// Part2
OpCodes.Ret
The first instruction stream (Part1
) is generated by iterating over all overloads
https://github.com/fsprojects/Foq/blob/master/Foq/Foq.fs#L573. Then, a valid overload is detected to generate code https://github.com/fsprojects/Foq/blob/master/Foq/Foq.fs#L576, which in turn triggers code generation for a ReturnValue(value, returnType)
(https://github.com/fsprojects/Foq/blob/master/Foq/Foq.fs#L223). I think this piece of code contains the "actual issue", as it does not differentiate between a void
return and the return of a single value. However, I could be wrong, as the surrounding of this code could compensate for this problem in most cases (except this one).
Additionally, we pass the check https://github.com/fsprojects/Foq/blob/master/Foq/Foq.fs#L580 if the function has a unit
or void
return (which I believe is correct). Depending on how we solve this problem in the first place, this could already avoid issuing duplicate return statements.
I can also prepare a PR if we decide on a possible way to fix this 😃
from foq.
@drivehappy, any thoughts about @m4rs-mt's approach?
from foq.
I can also prepare a PR if we decide on a possible way to fix this 😃
If you have a solution please raise a PR (preferably with a test that asserts it fixes this issue). I'm more than happy to review and merge.
from foq.
Related Issues (15)
- Support mocking multiple interfaces HOT 1
- Missing License HOT 1
- Please rename `Lib` directory to `lib` in the NuGet package HOT 3
- A mocked abstract base class is "not equal to itself"
- Can't mock an abstract class with an "internal set" virtual property HOT 2
- Issues asserting on constrained types HOT 1
- Is it possible to first get the abstract and then setup its behaviour?
- [Bug?] Cannot mock class with protected virtual method. HOT 1
- Foq error is very unhelpful for internal types
- How to mock a function (not a member)?
- ReturnFunc not working for int64 properties HOT 6
- Support for Xamarin Android HOT 3
- .net 4.6.1 HOT 1
- Release a new version HOT 7
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from foq.