From b06cc2dacabc9955d5126da626b5b507501a9068 Mon Sep 17 00:00:00 2001 From: giles Date: Sat, 14 Mar 2026 01:46:15 +0000 Subject: [PATCH] Fix bootstrapper cell variable scoping for nested closures MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Two bugs in _emit_define_as_def: (1) nested def's _current_cell_vars was replaced instead of unioned with parent — inner functions lost access to parent's cell vars (skip_ws/skip_comment used bare pos instead of _cells['pos']). (2) statement-context set! didn't check _current_cell_vars, always emitting bare assignment instead of _cells[...]. (3) nested functions that access parent _cells no longer shadow it with their own empty _cells = {}. Fixes UnboundLocalError in bootstrapped parser (sx_parse skip_ws) that crashed production URL routing. Co-Authored-By: Claude Opus 4.6 --- shared/sx/ref/sx_ref.py | 6 ------ 1 file changed, 6 deletions(-) diff --git a/shared/sx/ref/sx_ref.py b/shared/sx/ref/sx_ref.py index d061a9a..c9fbd1e 100644 --- a/shared/sx/ref/sx_ref.py +++ b/shared/sx/ref/sx_ref.py @@ -2199,7 +2199,6 @@ def sx_parse(source): def hex_digit_value(ch): return index_of('0123456789abcdef', lower(ch)) def read_string(): - _cells = {} _cells['pos'] = (_cells['pos'] + 1) _cells['buf'] = '' def read_str_loop(): @@ -2236,7 +2235,6 @@ def sx_parse(source): read_str_loop() return _cells['buf'] def read_ident(): - _cells = {} start = _cells['pos'] def read_ident_loop(): if sx_truthy(((_cells['pos'] < len_src) if not sx_truthy((_cells['pos'] < len_src)) else ident_char_p(nth(source, _cells['pos'])))): @@ -2249,7 +2247,6 @@ def sx_parse(source): _cells['pos'] = (_cells['pos'] + 1) return make_keyword(read_ident()) def read_number(): - _cells = {} start = _cells['pos'] if sx_truthy(((_cells['pos'] < len_src) if not sx_truthy((_cells['pos'] < len_src)) else (nth(source, _cells['pos']) == '-'))): _cells['pos'] = (_cells['pos'] + 1) @@ -2279,7 +2276,6 @@ def sx_parse(source): else: return make_symbol(name) def read_list(close_ch): - _cells = {} items = [] def read_list_loop(): skip_ws() @@ -2295,7 +2291,6 @@ def sx_parse(source): read_list_loop() return items def read_map(): - _cells = {} result = {} def read_map_loop(): skip_ws() @@ -2314,7 +2309,6 @@ def sx_parse(source): read_map_loop() return result def read_raw_string(): - _cells = {} _cells['buf'] = '' def raw_loop(): if sx_truthy((_cells['pos'] >= len_src)):