HS: fix repeat-in loop variable binding + dict insertion order (+4 tests)
Some checks failed
Test, Build, and Deploy / test-build-deploy (push) Failing after 40s

Two fixes:

(1) compiler.sx: remove `it` from hs-reserved-var?. `it` is the standard
HS loop variable for `repeat in` loops; renaming it to `_hs_lv_it` made
the body reference the outer (nil) `it` rather than the bound element.
Other reserved vars (meta, event, result) still get renamed to prevent
shadowing built-ins in misnamed loops.

(2) runtime.sx: hs-make-object now appends an `_order` list tracking
insertion order, mirroring the pattern used by other dict-building paths.
Without this, `for prop in obj` fell back to `(keys obj)` which gives
non-deterministic key order for objects with string keys.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-05-04 18:33:12 +00:00
parent d5aa8a2e74
commit 42184797f1
4 changed files with 22 additions and 16 deletions

View File

@@ -463,13 +463,7 @@
(list (quote fn) (list) body)))))))
(define
hs-reserved-var?
(fn
(name)
(or
(= name "meta")
(= name "event")
(= name "it")
(= name "result"))))
(fn (name) (or (= name "meta") (= name "event") (= name "result"))))
(define
emit-for
(fn

View File

@@ -2330,7 +2330,16 @@
((d {}))
(do
(for-each
(fn (pair) (dict-set! d (first pair) (nth pair 1)))
(fn
(pair)
(let
((name (first pair)))
(do
(dict-set! d name (nth pair 1))
(dict-set!
d
"_order"
(append (or (get d "_order") (list)) (list name))))))
pairs)
d))))

View File

@@ -463,13 +463,7 @@
(list (quote fn) (list) body)))))))
(define
hs-reserved-var?
(fn
(name)
(or
(= name "meta")
(= name "event")
(= name "it")
(= name "result"))))
(fn (name) (or (= name "meta") (= name "event") (= name "result"))))
(define
emit-for
(fn

View File

@@ -2330,7 +2330,16 @@
((d {}))
(do
(for-each
(fn (pair) (dict-set! d (first pair) (nth pair 1)))
(fn
(pair)
(let
((name (first pair)))
(do
(dict-set! d name (nth pair 1))
(dict-set!
d
"_order"
(append (or (get d "_order") (list)) (list name))))))
pairs)
d))))