microsoft / RulesEngine

A Json based Rules Engine with extensive Dynamic expression support
https://microsoft.github.io/RulesEngine/
MIT License
3.47k stars 528 forks source link

Comparisons with nullable types #558

Closed celi closed 5 months ago

celi commented 7 months ago

Hi, code like this

        decimal? d1 = null;
        var result = d1 < 20;

run in c# return false, but same comparison run in RulesEngine return true, why?

celi commented 7 months ago

I found that FastExpressionCompiler changes this behavior.

Changing line https://github.com/microsoft/RulesEngine/blob/9bcf4f334b7b98b4ab2d347522ff86b3e884afed/src/RulesEngine/ExpressionBuilders/RuleExpressionParser.cs#L60 to

return wrappedExpression.Compile();

fix this problem.

This is bug for me.

celi commented 7 months ago

Linked https://github.com/dadhi/FastExpressionCompiler/issues/380

abbasc52 commented 6 months ago

@celi i can maybe add option to disable fast compile if needed, it will be a tradeoff between performance vs accuracy Would that work for you?

celi commented 6 months ago

@abbasc52 Yes, please. I didn't test decrease of performance without FastExpressionCompiler yet, but I plan to do that. It will be easier with this switch.

abbasc52 commented 5 months ago

@celi can you share complete sample code to reproduce this issue?

celi commented 5 months ago

@abbasc52 https://github.com/celi/MsRulesEngineCompareWithNullBug

just run dotnet run in project folder