Passing null as a parameter
CollinAlpert opened this issue · 2 comments
When using null
in a lambda, e.g. SqlPredicate<IPerson> pred = p -> p.getName() == null;
it becomes a UnaryExpression
in the Expression tree and can be evaluated as such, which is great.
However when using a parameter that is null
, e.g.:
String nullParam = null;
SqlPredicate<IPerson> p = person -> person.getName() == nullParam;
it gets evaluated as a normal ConstantExpression
. Is there any way this could be changed?
You are not correct :-). It evaluates to a ParameterExpresson and you translate it to ConstantExpression via arguments lookup. JaQue is a parser, not an analyzer... Its goal is to create an expression tree out of Lambda and be as correct as possible in doing that. The rest is use case specific, and by doing an extra mile in one direction, I may create problems for another use case. The only acceptable bug is when JaQue creates a tree that is not same as developer originally wrote.
BTW, you could see that I released 2.3.0 version just recently. I didn't write release notes for it yet, but it fixes a bug, that from your perspective is probably a regression. We already discussed the nested Lambda. In the pre 2.3.0 version they appear both in the tree and in arguments (saw your code filtering them out). Actually this is wrong. The Lambda is passed in a parameter and is invoked via a parameter (see your SqlPredicate
implementation). So what was it doing inside a tree?? I copied it from arguments in place of the parameter. I created this "bug" deliberately during my composition implementation because I had a design flaw: there was no support for calling a lambda via a parameter. In 2.3.0 I added a new InvocableExpression
- DelegateExpression
, which requires an expression (delegate) to have a resultType
to be InvocableExpression
.
So in 2.3.0 the tree is fixed and matches the code. But if you will upgrade to it, you will need to resolve the Lambda from the delegate and arguments instead of having it directly as InvocationExpression
target.
I see, that helps me a lot. Thanks!!