akbasic_environment_set_label() files into the active scope, not the root #9

Open
opened 2026-08-02 19:04:15 -04:00 by tachikoma · 0 comments
Collaborator

Source: TODO.md §6 item 26 (at 9151438)

src/environment.c:246 walks up until obj->runtime->environment == obj, which is the currently
executing
scope, despite the comment above it saying "Only the top-level environment creates
labels".

So a LABEL reached inside a GOSUB or FOR body is filed into that scope and dies when the body
pops, while akbasic_runtime_scan_labels() (src/runtime.c:1286) files the same label into the
real root.

The consequence is that a prescanned label and a re-filed one behave differently, and which one
you get depends on whether control has passed through the LABEL statement inside a scope. Nothing
in either corpus does that, so nothing catches it.

The fix is one condition -- walk to parent == NULL -- plus a test that GOSUBs past a
LABEL and then branches to it from the top level.

Check it against the "LABEL still executes and re-files itself" deviation first, because
that behaviour is deliberate and the re-filing is the part worth keeping.

Files: src/environment.c:246, src/runtime.c:1286


Filed by Tachikoma (Claude Code, Opus 5, 1M context)

**Source:** TODO.md §6 item 26 (at 9151438) `src/environment.c:246` walks up until `obj->runtime->environment == obj`, which is the *currently executing* scope, **despite the comment above it saying "Only the top-level environment creates labels".** So a `LABEL` reached inside a `GOSUB` or `FOR` body is filed into that scope and dies when the body pops, while `akbasic_runtime_scan_labels()` (`src/runtime.c:1286`) files the same label into the real root. **The consequence is that a prescanned label and a re-filed one behave differently**, and which one you get depends on whether control has passed through the `LABEL` statement inside a scope. Nothing in either corpus does that, so nothing catches it. **The fix is one condition** -- walk to `parent == NULL` -- plus a test that `GOSUB`s past a `LABEL` and then branches to it from the top level. **Check it against the "`LABEL` still executes and re-files itself" deviation first**, because that behaviour is deliberate and the re-filing is the part worth keeping. **Files:** `src/environment.c:246`, `src/runtime.c:1286` --- Filed by Tachikoma (Claude Code, Opus 5, 1M context)
tachikoma added this to the 0.1.x milestone 2026-08-02 19:04:15 -04:00
tachikoma added the defectblast-radius:mediumstatus::grooming labels 2026-08-02 19:04:15 -04:00
Sign in to join this conversation.