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

Unable to cast negative number as a decimal #154

Open
JamesHill3 opened this issue Nov 28, 2023 · 2 comments
Open

Unable to cast negative number as a decimal #154

JamesHill3 opened this issue Nov 28, 2023 · 2 comments
Assignees

Comments

@JamesHill3
Copy link

JamesHill3 commented Nov 28, 2023

We use the this framework to evaluate user-created formulas where values are replaced at runtime. I offer that explanation only to justify the hideous C# I'm about to post.

The user-created expression/formula below is not able to be evaluated by the Eval-Expression framework:

Math.Round((((decimal)-2 / 2) - (decimal)0.0625 - ((decimal)2 / 2)) * 32) / 32

The error is:

Operator '-' cannot be applied to operands of type 'RuntimeType' and 'int'. The error occurred for expression "-" at position 22 near "-2 / 2) - (decimal)0.0625".

This same expression is evaluated successfully in dotnetfiddle.net.

Removing the '-' from the (decimal)-2 allows the evaluation framework to work.

UPDATE/EDIT:

I'd like to add that after further testing, the bug can be more easily reproduced: (decimal)-2.

@JonathanMagnan JonathanMagnan self-assigned this Nov 28, 2023
@JonathanMagnan
Copy link
Member

Hello @JamesHill3 ,

Thank you for reporting it. I can confirm that we can easily reproduce this bug and we will look at it to make a fix.

Best Regards,

Jon

@JonathanMagnan
Copy link
Member

Hello @JamesHill3 ,

The v6.0.4 has been released today.

We don't feel the fix is perfect yet, so we will discuss how we can further improve it. So far, we have found that is still possible to get some issues when using a variable or navigation path (instead of a type to cast) in parenthesis before the subtract sign.

Here is a working example: https://dotnetfiddle.net/NtRRYg

Best Regards,

Jon

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

2 participants