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

InvalidOperationException when comparing two nullable numeric values #276

Closed
Hakim83 opened this issue Feb 18, 2023 · 3 comments · Fixed by #277
Closed

InvalidOperationException when comparing two nullable numeric values #276

Hakim83 opened this issue Feb 18, 2023 · 3 comments · Fixed by #277

Comments

@Hakim83
Copy link

Hakim83 commented Feb 18, 2023

The following code was evaluating well till version 2.11.0

interpreter.Eval<bool>("((int?)5)>((double?)4)");

later versions (including current version 2.13.0), throws the following exception:

System.InvalidOperationException : The binary operator GreaterThan is not defined for the types 'System.Nullable`1[System.Int32]' and 'System.Nullable`1[System.Double]'

tested in .NET6

@metoule
Copy link
Contributor

metoule commented Feb 19, 2023

This was a side effect of #231,

The fix is to perform a better check to see if a method is applicable (by better matching generic types).

@Hakim83
Copy link
Author

Hakim83 commented Feb 20, 2023

Ok,
in fact I got the same exception when running non-nullable different types but using null conditional operator, e.g.
class Foo { public int var1; public double var2; }
then, following throws that exception:
interpreter.Eval("foo?.var1>foo?.var2")

@metoule
Copy link
Contributor

metoule commented Feb 20, 2023

That's the same error, since the null conditional operator is just syntactic sugar :)

int? var1 = null;
if (foo != null)
  var1 = foor.var1;

double? var2 = null;
if (foo != null)
  var2 = foor.var2;

return var1 > var2;

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

Successfully merging a pull request may close this issue.

2 participants