Skip to content
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

Bug when trying to upcast a delegate return type #185

Closed
israellot opened this issue Nov 14, 2021 · 3 comments · Fixed by #186
Closed

Bug when trying to upcast a delegate return type #185

israellot opened this issue Nov 14, 2021 · 3 comments · Fixed by #186
Labels

Comments

@israellot
Copy link
Contributor

var interpreter = new Interpreter().SetVariable("a", 123L);  
var del = interpreter.ParseAsDelegate<Func<object>>("a*2");
var interpreter = new Interpreter().SetVariable("a", 123L);  
var del = interpreter.ParseAsDelegate<Func<dynamic>>("a*2");

These simple examples used to run just fine on 2.8X and fails at 2.9.5.
I believe support to auto upcasting should be maintained.

@metoule
Copy link
Contributor

metoule commented Nov 14, 2021

Both examples worked with v2.8.1, but stopped working in v2.9.0, so it's linked to PR #140.
I'll investigate why it stopped working.

metoule added a commit to metoule/DynamicExpresso that referenced this issue Nov 14, 2021
…icitly object.

Force the return type of a lambda expression to typeof(void) to prevent the emission of a conversion expresssion.
Fixes dynamicexpresso#185
@metoule
Copy link
Contributor

metoule commented Nov 14, 2021

That was a side effect of the lambda expression support.

Background: the parser is able to correctly detect the type of an expression, but it emits a conversion expression from the actual type to the requested return type (so here, object).

When parsing a lambda expression, the return type is not known beforehand, so we use typeof(object) by default. That's an issue, because while the actual type was properly detected by the parser, it was lost due to a forced conversion to typeof(object). To prevent this, I no longer emitted the conversion expression if the return type was object, but that caused an issue if that's what's actually wanted!

To fix all this, when parsing a lambda expression, I now use typeof(void) to prevent the emission of the conversion expression.

metoule added a commit to metoule/DynamicExpresso that referenced this issue Nov 14, 2021
@israellot
Copy link
Contributor Author

Thanks @metoule ! I would go dig it myself and submit a PR later, but you were faster than me.

metoule added a commit that referenced this issue Nov 25, 2021
* No longer omit the conversion expression when the return type is explicitly object.
Force the return type of a lambda expression to typeof(void) to prevent the emission of a conversion expression.
Fixes #185

* Remove PrepareDelegateInvoke to avoid modifying the arguments list.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
3 participants