Skip to content

fix: static initialisers as constant expressions#1638

Merged
DavePearce merged 8 commits intomainfrom
1637-feat-using-named-constants-in-static-reference-tables
Apr 8, 2026
Merged

fix: static initialisers as constant expressions#1638
DavePearce merged 8 commits intomainfrom
1637-feat-using-named-constants-in-static-reference-tables

Conversation

@DavePearce
Copy link
Copy Markdown
Collaborator

@DavePearce DavePearce commented Apr 8, 2026

This adds support for static initialises for static memory to be compile-time constant expressions, rather than just fixed numbers.


Note

Medium Risk
Changes parsing/linking/typechecking/codegen for static memory contents and constant evaluation, which can affect program semantics and error reporting across the compiler pipeline. Risk is moderate due to new compile-time evaluation paths and overflow/underflow diagnostics.

Overview
Static memory initialisers are now parsed and stored as compile-time constant expressions (not just numeric literals). This threads expression-based Contents through AST (decl.Memory), parsing (parseStaticInitialiser), linking, and typing.

Codegen now evaluates static initialiser expressions at compile time via compileStaticInitialisers, and evalConstant was expanded to handle more operators (Sub/Div/Rem) while collecting syntax errors for overflow/underflow and cast overflow instead of panicking.

Tests and fixtures were updated/added to cover constant cycles, arithmetic overflow in constants/static initialisers, and static initialiser typing/unknown-symbol failures, plus a new unit test demonstrating constant-based static initialisation.

Reviewed by Cursor Bugbot for commit f02fa83. Bugbot is set up for automated code reviews on this repo. Configure here.

This adds support for static initialises for static memory to be
compile-time constant expressions, rather than just fixed numbers.
@DavePearce DavePearce linked an issue Apr 8, 2026 that may be closed by this pull request
@DavePearce DavePearce force-pushed the 1637-feat-using-named-constants-in-static-reference-tables branch from 8241b30 to 65e0de1 Compare April 8, 2026 11:12
This adds support for better error handling for static initialisers.
Previously initialiser errors were being missed, and this was a
significant issue.
Copy link
Copy Markdown

@cursor cursor bot left a comment

Choose a reason for hiding this comment

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

Cursor Bugbot has reviewed your changes and found 2 potential issues.

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, have a team admin enable autofix in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit 92d1f6a. Configure here.

@DavePearce DavePearce merged commit 4d0b5b8 into main Apr 8, 2026
28 checks passed
@DavePearce DavePearce deleted the 1637-feat-using-named-constants-in-static-reference-tables branch April 8, 2026 14:45
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.

feat: using named constants in static reference tables

1 participant