Giter VIP home page Giter VIP logo

Comments (3)

daveaglick avatar daveaglick commented on May 19, 2024

I've done a little more digging. I think the problem is that the decompiled IL won't contain a cast by design for certain compatible types. For example, if I put the following into LINQPad (I just picked an arbitrary enum):

StringComparison s = StringComparison.CurrentCultureIgnoreCase;
int x = (int)s % 10;

It generates the following IL:

IL_0001:  ldc.i4.1    
IL_0002:  stloc.0     // s
IL_0003:  ldloc.0     // s
IL_0004:  ldc.i4.s    0A 
IL_0006:  rem         
IL_0007:  stloc.1     // x

You can see there's no attempt to convert the enum to an int (which makes sense - enum is obviously a compiler construct). This looks almost identical to the IL generated by the following:

int i = 1;
int x = i % 10;

Which generates:

IL_0001:  ldc.i4.1    
IL_0002:  stloc.0     // i
IL_0003:  ldloc.0     // i
IL_0004:  ldc.i4.s    0A 
IL_0006:  rem         
IL_0007:  stloc.1     // x

So I think the problem is that while the IL we get back from Mono.Reflection is correct, the Processor class is not inferring casts when it should because they sometimes get lost in the journey from MethodInfo to IL as part of the optimization.

The solution would be to check for these cases and insert Expression.Convert() calls into the expression tree generated by the Processor when needed. I'll take a look and see if I can find any OSS decompiler code that already implements a check like this.

from delegatedecompiler.

hazzik avatar hazzik commented on May 19, 2024

We already have AdjustType method which should do this. I'll check later.

from delegatedecompiler.

daveaglick avatar daveaglick commented on May 19, 2024

Great - thanks. Hadn't noticed the AdjustType method. Just let me know if there's anything else I can do to help with this.

from delegatedecompiler.

Related Issues (20)

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.