Skip to content

fix(codegen): declare loop-local drawing-object handles (line/label/box)#24

Merged
luisleo526 merged 1 commit into
mainfrom
fix/skip-expr-local-vardecl-drop
Jun 28, 2026
Merged

fix(codegen): declare loop-local drawing-object handles (line/label/box)#24
luisleo526 merged 1 commit into
mainfrom
fix/skip-expr-local-vardecl-drop

Conversation

@luisleo526

Copy link
Copy Markdown
Contributor

Problem

A variable assigned from a skipped visual call (line.new / label.new / box.new / …) was declared only when the namespace was table (SKIP_VAR_TYPES). For the other drawing namespaces the declaration was dropped. In script/if scope the var is a class member (declared anyway), but as a for-loop local it became undeclared:

var aoLines = array.new<line>()
for k = 1 to aoCount
    ln = line.new(...)        // dropped
    array.push(aoLines, ln)   // -> aoLines.push_back(ln);  // no `ln`
error: use of undeclared identifier 'ln'

Found running real-world strategies through the engine — common in webhook/DCA bots that draw AO level lines in a loop (11 strategies in the test set hit this).

Fix

Always emit a default-valued local declaration for skip-expr assignments. The value is inert (drawing ops have no backtest effect) but references must compile. Removes the now-unused SKIP_VAR_TYPES import.

Tests / regression

  • New tests/test_codegen_drawing_handles.py (line + label handles in a loop).
  • No corpus regression: all 258 corpus probes transpile byte-identically with vs without this change (no corpus probe uses this pattern).
  • End-to-end: a real strategy with this pattern compiles with 0 errors when combined with fix(codegen): escape C++ string literals (quotes/backslash/newline) #23 (string escaping).

🤖 Generated with Claude Code

A variable assigned from a skipped visual call (line.new / label.new / box.new
/ ...) was only declared when the namespace was `table` (SKIP_VAR_TYPES); for
other drawing namespaces the declaration was dropped. In script/if scope the var
is a class member (declared anyway), but as a *for-loop local* it became
undeclared, so e.g.

    ln = line.new(...)
    array.push(aoLines, ln)

emitted `aoLines.push_back(ln);` with no `ln` -> "use of undeclared identifier
'ln'". Common in webhook/DCA strategies that draw AO level lines in a loop.

Always emit a default-valued local declaration for skip-expr assignments — the
value is inert (drawing ops have no backtest effect) but references must compile.
Removes the now-unused SKIP_VAR_TYPES import.

Adds regression tests. No corpus regression: all 258 corpus probes transpile
byte-identically with vs without this change.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@luisleo526 luisleo526 merged commit 5d253bf into main Jun 28, 2026
9 checks passed
@luisleo526 luisleo526 deleted the fix/skip-expr-local-vardecl-drop branch June 28, 2026 08:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant