catch a bug in while loops

This commit is contained in:
2023-07-10 15:56:23 -06:00
parent 034e83827c
commit fe882d1969
3 changed files with 13 additions and 1 deletions

View File

@@ -334,7 +334,7 @@ class SpecialForms {
function whileForm(invert:Bool, wholeExp:ReaderExp, args:Array<ReaderExp>, k:KissState) {
var funcName = if (invert) "until" else "while";
var b = wholeExp.expBuilder();
var cond = k.convert(b.callSymbol("Prelude.truthy", [args[0]]));
var cond = k.convert(b.callSymbol("Prelude.truthy", [args.shift()]));
if (invert) {
cond = macro !$cond;
cond = b.haxeExpr(cond);

View File

@@ -355,6 +355,10 @@ class BasicTestCase extends Test {
_testIntersect();
}
function testWhile() {
_testWhile();
}
function testWhileLet() {
_testWhileLet();
}

View File

@@ -675,6 +675,14 @@ From:[(assert false (+ \"false \" \"should \" \"have \" \"been \" \"true\"))]" m
)
(Assert.pass))
(function _testWhile []
(let [max 8
&mut current 0
&mut iterations 0]
(while (>= max (+= current 1))
(+= iterations 1))
(Assert.equals 8 iterations)))
(function _testWhileLet []
(let [&mut idx 0
lines ["a" "b" "c"]