VirtLang v4.1.1 Release Notes: Critical Short-Circuiting Fix for Logical Operators
We are issuing a patch release, VirtLang v4.1.1, to address a critical bug in the logical operator implementation introduced in v4.1.0. This update ensures that the && and || operators correctly perform short-circuit evaluation, a fundamental behavior for these operators in modern languages.
🐛 Bug Fixes
Corrected Short-Circuit Evaluation for && and || Operators
- Problem: In v4.1.0, the right-hand side of a logical expression was always evaluated, regardless of the value of the left-hand side. This violated the principle of short-circuiting. For example, in an expression like
false && someFunction(), thesomeFunction()was incorrectly called even though the outcome of the expression was already determined by thefalsevalue. This could lead to unexpected side effects and performance degradation. - Solution: The evaluation logic for logical expressions (
evaluator/evalLogicEx.go) has been rewritten to correctly implement short-circuiting. The interpreter now behaves as expected:- For
&&(AND), the right-hand side is only evaluated if the left-hand side is truthy. - For
||(OR), the right-hand side is only evaluated if the left-hand side is falsy.
- For
- Impact: This fix restores the correct, expected behavior of the language, prevents unintended function calls, and improves performance by avoiding unnecessary evaluations.
⚙️ Other Improvements
- Documentation: The auto-generated API documentation (
DOCS.md) has been updated to include the missing entries for theLogicalExprandLogicalOperatortypes that were introduced in v4.1.0. - Code Quality: Minor refactoring was done in the evaluator for better structure, and an error message for unknown logical operators was corrected from "Unknown comparison operator" to "Unknown logical operator."
🧪 Testing
- To ensure the robustness of this fix, new, specific test cases have been added to the evaluator suite.
- These tests use functions with side effects (modifying an array) to rigorously verify that the right-hand side of an expression is not executed when a short-circuit should occur.
⚠️ Upgrade Notes
- This is a critical bug-fix release.
- All users of v4.1.0 are strongly encouraged to upgrade to v4.1.1 immediately to ensure correct program execution.
- Code that unintentionally relied on the buggy, non-short-circuiting behavior will now execute correctly, which may alter program flow to its intended state.
Acknowledgements
Thank you to @dev-kas for quickly identifying and resolving this critical issue.