Repository navigation
VirtLang v2.1.1
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/elseStatement Evaluation:- Problem: Prior versions of VirtLang incorrectly ignored
elseifandelseblocks withinifstatements. Only the primaryifblock's condition was evaluated, leading to code withinelseifandelsebranches 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
ifstatements has been completely revised to ensure thatelseifandelsebranches are evaluated correctly. The interpreter now processes conditions in the following order:- Evaluates the condition of the initial
ifstatement. If true, theifblock is executed. - If the initial
ifcondition is false, the interpreter evaluates the condition(s) of each subsequentelseifblock sequentially. If anelseifcondition is true, its corresponding block is executed, and the rest of the branches are skipped. - If all
ifandelseifconditions evaluate to false, the interpreter executes the code within theelseblock (if one is present).
- Evaluates the condition of the initial
- Problem: Prior versions of VirtLang incorrectly ignored
Core Interpreter Enhancements
- Truthiness Helper Function (
helpers.IsTruthy): A new helper function,IsTruthy, has been introduced to consolidate the logic for determining whether aRuntimeValueshould be considered "truthy" in boolean contexts. The function covers all existing VirtLang types:Boolean:trueis truthy,falseis 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.goto validate the corrected behavior ofif/elseif/elsestatements and theIsTruthyhelper 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/elsestatements 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!