Skip to content

VirtLang v2.1.1

Choose a tag to compare

@dev-kas dev-kas released this 19 May 11:42
· 74 commits to master since this release

VirtLang v2.1.1 Release Notes: Bug Fix for if/elseif/else Statements

We are releasing VirtLang v2.1.1 to address a critical bug in the evaluation of if/elseif/else statements. This patch ensures that all conditional branches are correctly evaluated, restoring expected program behavior and enabling more complex logic.

Bug Fixes

  • if/elseif/else Statement Evaluation:
    • Problem: Prior versions of VirtLang incorrectly ignored elseif and else blocks within if statements. Only the primary if block's condition was evaluated, leading to code within elseif and else branches being skipped entirely, regardless of their conditions. This made it impossible to create branching logic with more than a single condition.
    • Solution: The evaluation logic for if statements has been completely revised to ensure that elseif and else branches are evaluated correctly. The interpreter now processes conditions in the following order:
      1. Evaluates the condition of the initial if statement. If true, the if block is executed.
      2. If the initial if condition is false, the interpreter evaluates the condition(s) of each subsequent elseif block sequentially. If an elseif condition is true, its corresponding block is executed, and the rest of the branches are skipped.
      3. If all if and elseif conditions evaluate to false, the interpreter executes the code within the else block (if one is present).

Core Interpreter Enhancements

  • Truthiness Helper Function (helpers.IsTruthy): A new helper function, IsTruthy, has been introduced to consolidate the logic for determining whether a RuntimeValue should be considered "truthy" in boolean contexts. The function covers all existing VirtLang types:
    • Boolean: true is truthy, false is falsy.
    • Number: Non-zero numbers are truthy, zero is falsy.
    • String: Non-empty strings (strings with length greater than 2 to exclude empty string representations \"\") are truthy, empty strings are falsy.
    • Nil: Always falsy.
    • Object, Array, Function, NativeFN, ClassInstance, Class: Always truthy.
      This ensures consistent truthiness behavior across the interpreter.

Testing

  • A comprehensive test suite has been added to evaluator_test.go to validate the corrected behavior of if/elseif/else statements and the IsTruthy helper function. The tests cover various scenarios, including all the different combinations of conditional branching and truthiness checks.

Known Issues and Limitations

  • None.

Upgrade Notes

  • This is a bug fix release. All VirtLang programs using if/elseif/else statements are strongly encouraged to upgrade to v2.1.1. Existing code that relied on the previous incorrect behavior will now function as intended, but it is advised to review your logic to ensure it aligns with the correct conditional evaluation.

Getting Started

Refer to the README.md and the generated DOCS.md for information on how to use the interpreter or contribute to the project.

Acknowledgements

A thank you to @dev-kas for identifying and resolving this issue!