You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Parser: inner if-chain ending in 'else if' swallows the outer chain's next else at the same column #629
A dangling-else variant: an inner if-chain whose LAST arm is else if captures the outer chain's following else if/else at the outer column, silently miscompiling. Found while writing compiler code (worked around with a helper). Related to the §7.5 dangling-else fix but a distinct shape (inner chain ends in else-if, not a bare inner if).
Spec §7.5 (dangling-else, indentation-sensitive)
Repro
Being reduced; the shape is: outer if a: ... else if b: (inner: if c: X else if d: Y) else if e: Z — Z binds to the inner chain. Probe files exist under scratchpad/tartest/norm{e,f,h,i}.w (fail) vs d (works). Will attach a minimal .w.
Fixed in 508659f; build + fixpoint + full test suite green. Root cause: parse_if_expr computed is_stmt_if/if_col from each arm's own if token, so an else if arm (not first-on-line, column-shifted by else ) bypassed the §7.5 dangling-else rejection and captured the outer chain's next else. The chain now threads the original if's column/statement-ness through the recursion.
Because the compiler is self-hosted, an instrumented sweep (old-vs-new parse decision diff over the whole tree) found 10 flipped sites — in every one the new parse matches the written indentation intent, and the old parse had silently disabled the outer arms. Notable repairs that ride along: lib/std/build.w tool_path_normalize was completely broken ('src/x.w' → '.'), now correct (fixes ToolFs containment comparisons); build/sdk.w SDK packaging's bin/ tool-selection arm was dead; SemaCheck function/closure tail-return checks and the comprehension expected-type diagnostic were dead (one fixture updated to the now-live intended diagnostic). Full list in the commit message. Pinned by test/behavior/behav_dangling_else_if_chain.w.
Activity
ehartford commentedon Jul 4, 2026
Fixed in 508659f; build + fixpoint + full test suite green. Root cause:
parse_if_exprcomputedis_stmt_if/if_colfrom each arm's owniftoken, so anelse ifarm (not first-on-line, column-shifted byelse) bypassed the §7.5 dangling-else rejection and captured the outer chain's nextelse. The chain now threads the original if's column/statement-ness through the recursion.Because the compiler is self-hosted, an instrumented sweep (old-vs-new parse decision diff over the whole tree) found 10 flipped sites — in every one the new parse matches the written indentation intent, and the old parse had silently disabled the outer arms. Notable repairs that ride along:
lib/std/build.w tool_path_normalizewas completely broken ('src/x.w' → '.'), now correct (fixes ToolFs containment comparisons);build/sdk.wSDK packaging's bin/ tool-selection arm was dead; SemaCheck function/closure tail-return checks and the comprehension expected-type diagnostic were dead (one fixture updated to the now-live intended diagnostic). Full list in the commit message. Pinned bytest/behavior/behav_dangling_else_if_chain.w.Fix #629: an else-if arm no longer swallows the outer chain's else
Fix #592: 'with check <compiler file>' no longer loads modules twice