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

Can't compare null parameter to a constant #45

Closed
altso opened this issue Jun 25, 2020 · 0 comments · Fixed by #46
Closed

Can't compare null parameter to a constant #45

altso opened this issue Jun 25, 2020 · 0 comments · Fixed by #46

Comments

@altso
Copy link
Contributor

altso commented Jun 25, 2020

The following test fails with an exception below. As a user, I would expect it to pass. I can create a PR with a fix if you agree it's a bug.

[Fact]
public void ShouldCompareNullableNullToNonNullable()
{
    var e = new Expression("[x] = 5", EvaluateOptions.AllowNullParameter);

    e.Parameters["x"] = null;
    Assert.False((bool)e.Evaluate());
}
System.InvalidCastException
Null object cannot be converted to a value type.
   at System.Convert.ChangeType(Object value, Type conversionType, IFormatProvider provider)
   at NCalc.Domain.EvaluationVisitor.CompareUsingMostPreciseType(Object a, Object b) in \src\NCalc\Domain\EvaluationVisitor.cs:line 65
   at NCalc.Domain.EvaluationVisitor.Visit(BinaryExpression expression) in \src\NCalc\Domain\EvaluationVisitor.cs:line 160
   at NCalc.Domain.BinaryExpression.Accept(LogicalExpressionVisitor visitor) in \src\NCalc\Domain\BinaryExpression.cs:line 20
   at NCalc.Expression.Evaluate() in \src\NCalc\Expression.cs:line 323
   at NCalc.Tests.Fixtures.ShouldCompareNullableNullToNonNullable() in \test\NCalc.Tests\Fixtures.cs:line 96
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.

1 participant