Skip to content

Nullable variables (int?) cause error on evaluation when value is null #368

@maharateeq

Description

@maharateeq

When setting a nullable variable (int?) with a null value, DynamicExpresso throws an evaluation error instead of handling the expression correctly.

var interpreter = new DynamicExpresso.Interpreter();

int? MyVar = null;

interpreter.SetVariable("MyValue", MyVar, typeof(int?));

var result = interpreter.Eval("(MyValue ?? 0) == 2");

Event These Evaluation Fails :

((int?)2 ?? 0) == 2      // Should be true, but throws
((int?)null ?? 0) == 2   // Should be false, but throws

Expected behaviour : The expression should evaluate without error and return false.

Actual behavior: It throws an InvalidOperationException.

Expected issue : DynamicExpresso treats (nullable ?? value) as returning object instead of the underlying type (int in this case).

Can someone please help me identify is it a bug/my wrong of of using and some other way possible to handle the scenario.

I am using Version : 2.19.2 (Latest as of now)

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions