Skip to content

Commit

Permalink
Merge pull request #906 from camunda/864-backport-1.16
Browse files Browse the repository at this point in the history
[Backport 1.16] fix: Unary-test behavior with special input variable `?`
  • Loading branch information
remcowesterhoud authored Aug 27, 2024
2 parents 0ebbedd + b324e88 commit 3d75a46
Show file tree
Hide file tree
Showing 14 changed files with 1,165 additions and 1,080 deletions.
11 changes: 11 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -328,6 +328,17 @@
<className>org/camunda/feel/syntaxtree/Range</className>
<differenceType>8001</differenceType>
</ignored>
<!-- ignore auto-generated Scala functions -->
<ignored>
<className>org/camunda/feel/syntaxtree/**</className>
<differenceType>7002</differenceType>
<method>scala.Function1 andThen(scala.Function1)</method>
</ignored>
<ignored>
<className>org/camunda/feel/syntaxtree/**</className>
<differenceType>7002</differenceType>
<method>scala.Function1 compose(scala.Function1)</method>
</ignored>
</ignored>
</configuration>
</plugin>
Expand Down
8 changes: 5 additions & 3 deletions src/main/scala/org/camunda/feel/FeelEngine.scala
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import org.camunda.feel.FeelEngine.{
import org.camunda.feel.context.{Context, FunctionProvider, VariableProvider}
import org.camunda.feel.impl.interpreter.{BuiltinFunctions, EvalContext, FeelInterpreter}
import org.camunda.feel.impl.parser.{ExpressionValidator, FeelParser}
import org.camunda.feel.syntaxtree.{Exp, ParsedExpression, ValError}
import org.camunda.feel.syntaxtree.{Exp, ParsedExpression, ValError, ValFatalError}
import org.camunda.feel.valuemapper.ValueMapper.CompositeValueMapper
import org.camunda.feel.valuemapper.{CustomValueMapper, ValueMapper}

Expand Down Expand Up @@ -205,9 +205,11 @@ class FeelEngine(

private def eval(exp: ParsedExpression, context: EvalContext): EvalExpressionResult = {
interpreter.eval(exp.expression)(context) match {
case ValError(cause) =>
case ValError(cause) =>
Left(Failure(s"failed to evaluate expression '${exp.text}': $cause"))
case value => Right(valueMapper.unpackVal(value))
case ValFatalError(cause) =>
Left(Failure(s"failed to evaluate expression '${exp.text}': $cause"))
case value => Right(valueMapper.unpackVal(value))
}
}

Expand Down
6 changes: 4 additions & 2 deletions src/main/scala/org/camunda/feel/impl/DefaultValueMapper.scala
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ import org.camunda.feel.syntaxtree.{
ValDateTime,
ValDayTimeDuration,
ValError,
ValFatalError,
ValFunction,
ValList,
ValLocalDateTime,
Expand Down Expand Up @@ -170,8 +171,9 @@ class DefaultValueMapper extends CustomValueMapper {
}.toMap
)

case f: ValFunction => Some(f)
case e: ValError => Some(e)
case f: ValFunction => Some(f)
case e: ValError => Some(e)
case fatalError: ValFatalError => Some(fatalError)

case _ => None
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
package org.camunda.feel.impl.builtin

import org.camunda.feel.logger
import org.camunda.feel.syntaxtree.{Val, ValError, ValFunction, ValNull}
import org.camunda.feel.syntaxtree.{Val, ValError, ValFatalError, ValFunction, ValNull}

object BuiltinFunction {

Expand All @@ -34,12 +34,13 @@ object BuiltinFunction {
}

private def error: PartialFunction[List[Val], Any] = {
case vars if (vars.exists(_.isInstanceOf[ValError])) =>
vars.filter(_.isInstanceOf[ValError]).head.asInstanceOf[ValError]
case e => {
logger.warn(s"Suppressed failure: illegal arguments: $e")
case args if args.exists(_.isInstanceOf[ValFatalError]) =>
args.find(_.isInstanceOf[ValFatalError])
case args if args.exists(_.isInstanceOf[ValError]) => args.find(_.isInstanceOf[ValError])
case args =>
val argumentList = args.map("'" + _ + "'").mkString(", ")
logger.warn(s"Suppressed failure: Illegal arguments: $argumentList")
ValNull
}
}

}
Loading

0 comments on commit 3d75a46

Please sign in to comment.