camunda/feel-scala

A context entry gets overridden by variable within a context liternal

Closed this issue · 3 comments

Describe the bug
A context literal can access the previous context entries by their context key. In the following example, the context accesses the entry a. A variable with the same name a is provided by the context.

{
  a: 10,
  b: a * 10
}

Since version 1.16.2, the FEEL engine evaluates the expression differently if the context contains a variable a. The context entry a gets overridden by the variable a. It seems to be an issue with the variable resolution.

This issue happens only if the context is provided by a custom context (i.e. not a static context). This is the case with the integration in Camunda 7's DMN engine and Zeebe.

To Reproduce
Use the following test case of the FEEL engine to reproduce the issue:

  "A context literal" should "access a previous entry" in {
    evaluateExpression(
      expression =
        "{a: 10, b: a * 10}",
      context = new MyContext                                 // --> this is failing
      // variables = Map("a" -> 0) --> this is working
    ) should returnResult(100)
  }

  class MyContext extends CustomContext {

    val vars = Map("a" -> 0)

    override def variableProvider: VariableProvider = new VariableProvider {
      override def getVariable(name: String): Option[Any] = vars.get(name)

      override def keys: Iterable[String] = vars.keys
    }
  }

Expected behavior
In a context literal, the previous context entries are not overridden by the context.

Environment

@d-molotchko-cap thank you for reporting. 👍 The reproducer project https://github.com/CapBPM/dmn-evaluation-context-issue was very helpful. 🚀

I changed the description of the issue to bring the focus to the issue in the FEEL engine.

This issue is closely related to #765.

Workaround

Use a different name for the variable or the context entry. If the variable name is different from the context entry key then the previous context entry is not overridden.