sklose / NCalc2

expression evaluator for .NET with built-in compiler
MIT License
166 stars 58 forks source link

Comparing null to custom function crashes #33

Closed rhaikonen closed 4 years ago

rhaikonen commented 5 years ago

Expression like "F(1) == null", where F(1) is custom function, throws exception: System.NullReferenceException : Object reference not set to an instance of an object. at System.Object.GetType() at NCalc.Domain.EvaluationVisitor.CompareUsingMostPreciseType(Object a, Object b) at NCalc.Domain.EvaluationVisitor.Visit(BinaryExpression expression) at NCalc.Expression.Evaluate()

F(1) can return null or not null objects.

This is an issue with all known Ncalc clones, even with the original, except Ncalc-Edge 1.4.1.000. We are forced to use that version and I'd like to use your much faster one.

kfrancis commented 4 years ago

@rhaikonen Can you write some code here that I can implement in a test to try and correct this?

kfrancis commented 4 years ago

@rhaikonen I can't quite get a test that matches what you're describing, but see if that pull request helps.