Skip to content

Fix evaluateExpression for proper handling of literals VS instance names #554

@AntoineGautier

Description

@AntoineGautier

Currently, we have the following properties in templates.json:

      "value": {
        "operator": "none",  // unnecessary wrapping of bare Boolean
        "operands": [
          true  
        ]
      },
// ...
      "enable": "have_chiWat"  // client-side value resolution fails

While literal strings – which are escaped in modelica-json – are stored unescaped "\"String literal\"" → "String literal".

The logic is backwards.

  • In the first case we should simply store "value": true since we have a bare Boolean, so really no need for the expression wrapper with "operator": "none".

  • In the second case, there is now way on the client side to distinguish between literal strings and instance names. If anywhere, the expression wrapper with "operator": "none" should be used here, for the client to resolve. (*)

(*) Another option would be to store literal strings with escape characters in templates.json. However, the standard practice in data interchange (JSON, HTML forms, REST APIs) is to store strings as plain strings (unescaped). To stick to that practice, the distinction between plain strings and instance names should rather be structural in templates.json.

Side Issue – Invalid String Comparison

With string-type variables such as parameter String str = "AAA", the client would fail evaluating the following equation str == "AAA". The function resolveToValue is called on each operand and returns null if the instance lookup fails. So the equation becomes "AAA" === null after lookup, which evaluates to false.
Enumeration-type comparison succeeds though because of isModelicaPath early return inside resolveToValue.
So the following equation is properly handled by the client.

              {
                "operator": "==",
                "operands": [
                  "secOutRel.typSecRel", // resolveToValue returns the actual variable value
                  "Buildings.Templates.AirHandlersFans.Types.ReliefReturnSection.ReturnFan" // resolveToValue returns it as-is because `isModelicaPath` returns true
                ]
              },

Metadata

Metadata

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions