Git Product home page Git Product logo

Comments (3)

m4rs-mt avatar m4rs-mt commented on May 26, 2024

@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.

stackedsax avatar stackedsax commented on May 26, 2024

@drivehappy, any thoughts about @m4rs-mt's approach?

from foq.

saul avatar saul commented on May 26, 2024

@m4rs-mt

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.