Bugfix
Parsing already fails with the following TL script:
switch (1) { 0: false; 1: true; }
Search expression: Undefined variable '<synthetic>'.
While the same works with switch (0). Findings so far:
- It seems to fail for all numbers != 0.
- Further case statements, for example for 2, do not change the behavior.
- A default statement does not change the behavior.
- A different result type, such as String instead of Boolean, does not change the behavior.
- Getting the value from a variable does not change the behavior.
- Calculating the value in a trivial way(switch (10-9)) does not change the behavior.
- Parsing the value from a string makes the error disappear.
This is a simplified example. The error occurred when I wanted to build and test a TL script expression in the script console. As soon as I leave the input field of the script console, the above error occurs. It is not necessary to execute the script.
Evaluation
Error in the constant folding of the TL-Script compiler. The problem always occurs if the input of the switch block can already be evaluated during translation. In this specific example, the only reason why the error does not occur with 0 is because the first branch of the switch block is then selected.
Test
- test.com.top_logic.model.search.expr.TestSearchExpression.testSwitchLiteral()