Skip to content

fix(engine): report diagnostic for empty source instead of IndexError#54

Merged
michaelkamprath merged 2 commits into
michaelkamprath:mainfrom
SAY-5:fix/empty-source-indexerror
May 20, 2026
Merged

fix(engine): report diagnostic for empty source instead of IndexError#54
michaelkamprath merged 2 commits into
michaelkamprath:mainfrom
SAY-5:fix/empty-source-indexerror

Conversation

@SAY-5

@SAY-5 SAY-5 commented May 19, 2026

Copy link
Copy Markdown
Contributor

Compiling an empty source file crashed with IndexError: list index out of range at engine.py because compilable_line_obs[-1] was accessed on an empty list. The engine now reports a clear source file contains no compilable lines diagnostic in that case. Closes #53.

@SAY-5 SAY-5 requested a review from michaelkamprath as a code owner May 19, 2026 06:39

@michaelkamprath michaelkamprath left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the fix! The core change is correct — diagnostic_reporter.error() calls sys.exit(), so the IndexError crash on the next line is properly prevented. A few minor suggestions below.

Comment thread src/bespokeasm/assembler/engine.py
Comment thread test/test_engine.py
@SAY-5

SAY-5 commented May 19, 2026

Copy link
Copy Markdown
Contributor Author

Moved the guard before the sort and switched to not compilable_line_obs as suggested. On the comments-only variant: with the test config a comments-only file still produces line objects, so it does not exercise this empty-list path; kept the zero-byte baseline test instead.

@michaelkamprath michaelkamprath left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the contribution!

closes #53

@michaelkamprath michaelkamprath merged commit 0a8ab2b into michaelkamprath:main May 20, 2026
4 checks passed
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.

IndexError when compiling an empty source file

2 participants