-
-
Notifications
You must be signed in to change notification settings - Fork 62
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
Problems with casting under certain conditions #30
Comments
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):
It generates the following IL:
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:
Which generates:
So I think the problem is that while the IL we get back from The solution would be to check for these cases and insert |
We already have AdjustType method which should do this. I'll check later. |
Great - thanks. Hadn't noticed the AdjustType method. Just let me know if there's anything else I can do to help with this. |
It appears as though inline casts are getting eaten, but only under certain conditions. I started out noticing this for enums. For example, consider the following test:
This works fine. However, this test does not:
It fails with System.InvalidOperationException : The binary operator Modulo is not defined for the types 'DelegateDecompiler.Tests.EnumTests+TestEnum' and 'System.Int32'.
This also doesn't work:
The error this time is System.InvalidOperationException : An expression of type 'DelegateDecompiler.Tests.EnumTests+TestEnum' cannot be used to initialize an array of type 'System.Int32'
I figured out this wasn't just an enum problem because this test also fails:
System.InvalidOperationException : The binary operator Equal is not defined for the types 'System.Int16' and 'System.Int32'.
When stepping through the
Processor.Process()
method, it doesn't appear as though any IL was generated for the casts in these cases. I assume the issue either lies withMono.Reflection
or with the .NET methodMethodBase.GetMethodBody()
whichMono.Reflection
uses. Unfortunately that makes it difficult to figure out how to fix. And since the exceptions are being thrown in theProcessor
during decompilation, it's not like the expression tree can be walked to add the casts back in (because there is no expression tree yet).The text was updated successfully, but these errors were encountered: