Skip to content

Align constant definitions in nested blocks - #1651

Merged
BradLewis merged 1 commit into
DanielGavin:masterfrom
giuinktse7:fix/align-constant-definitions-nested-blocks
Sep 1, 2026
Merged

Align constant definitions in nested blocks#1651
BradLewis merged 1 commit into
DanielGavin:masterfrom
giuinktse7:fix/align-constant-definitions-nested-blocks

Conversation

@giuinktse7

Copy link
Copy Markdown
Contributor

The setting align_constant_definitions currently only applies to file-level declarations. Constants inside procedures and nested control-flow blocks remain unaligned.

Note: I may be misunderstanding the intended behavior, but I found the current behavior surprising and believe this is a feature gap. You can just close this PR if the current behavior is intentional.

Cause

The constant alignment map is populated for file.decls, but nested statement lists are not scanned before formatting:

main :: proc() {
      SHORT :: 1
      LONGER_NAME :: 2
}

Fix

Compute constant alignment in the Block_Stmt visitor before calling visit_block_stmts.

All braced bodies ultimately pass through this visitor, so the option now applies consistently inside procedures, if, when, and loop blocks:

main :: proc() {
      SHORT       :: 1
      LONGER_NAME :: 2
}

Verification

Added snapshot coverage for constants inside:

  • Procedure bodies
  • if blocks
  • when blocks
  • Loop bodies

The complete odinfmt snapshot suite passes.

Compute constant alignment for each Block_Stmt so declarations inside procedures, conditionals, when statements, and loops are aligned.
@BradLewis
BradLewis merged commit 6f77fb8 into DanielGavin:master Sep 1, 2026
0 of 3 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.

2 participants