Skip to content

Commit

Permalink
feat: handle non-existing variables in comparisons
Browse files Browse the repository at this point in the history
Before when we encountered a non-existing variable in a comparison it would result in an error: "no variable found for name 'x'".
This commit changes this so we can deal with non-existing variables. They now get treated as ValNull and the comparison succeeds without errors.
  • Loading branch information
remcowesterhoud committed Jul 6, 2023
1 parent 2f6b705 commit 86e4c8c
Showing 1 changed file with 4 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -588,6 +588,8 @@ class FeelInterpreter {
x match {
case ValNull => f(c(ValNull, y.toOption.getOrElse(ValNull)))
case x if (y == ValNull) => f(c(x.toOption.getOrElse(ValNull), ValNull))
case _ : ValError => f(c(ValNull, y.toOption.getOrElse(ValNull)))
case _ if (y.isInstanceOf[ValError]) => f(c(ValNull, x.toOption.getOrElse(ValNull)))
case ValNumber(x) => withNumber(y, y => f(c(x, y)))
case ValBoolean(x) => withBoolean(y, y => f(c(x, y)))
case ValString(x) => withString(y, y => f(c(x, y)))
Expand Down Expand Up @@ -657,10 +659,8 @@ class FeelInterpreter {
c: (Val, Val) => Boolean,
f: Boolean => Val)(implicit context: EvalContext): Val =
x match {
case ValNull => withVal(y, y => ValBoolean(false))
case _ if (y == ValNull) => withVal(x, x => ValBoolean(false))
case _ if (!x.isComparable) => ValError(s"$x is not comparable")
case _ if (!y.isComparable) => ValError(s"$y is not comparable")
case _ if (!x.isComparable) => ValNull
case _ if (!y.isComparable) => ValNull
case _ if (x.getClass != y.getClass) =>
ValError(s"$x can not be compared to $y")
case _ => f(c(x, y))
Expand Down

0 comments on commit 86e4c8c

Please sign in to comment.