Skip to content

Don't leak an expression body's indent into later declarations - #2365

Open
eyupcanakman wants to merge 1 commit into
square:mainfrom
eyupcanakman:fix/expression-body-runaway-indent-1421
Open

Don't leak an expression body's indent into later declarations#2365
eyupcanakman wants to merge 1 commit into
square:mainfrom
eyupcanakman:fix/expression-body-runaway-indent-1421

Conversation

@eyupcanakman

Copy link
Copy Markdown
Contributor

An expression body that opens or closes an indent leaks it into every declaration after it, so each following function lands two spaces deeper than the last. Deeper nesting throws cannot unindent instead.

CodeBlock.trim() strips no-arg placeholders from both ends, dropping one half of a pair while its partner stays behind. It now takes them back from either end until nothing is left unmatched.

A body that opens an indent before the returned expression emits as a block body now, since the trimmed block no longer starts with the return. Same code, different shape. Most of the diff is tests, one per broken shape.

Fixes #1421.

  • docs/changelog.md has been updated if applicable.
    • Changes not visible to library consumers, such as build script, documentation, or test code updates, don't need to
      be added to the changelog.
  • CLA signed.

A function body that opens or closes an indent had that half trimmed away while its partner stayed, so CodeWriter kept the wrong level for every declaration after it.
Deeper cases threw cannot unindent instead.
Trimming now takes placeholders back from either end until nothing in the block is left unmatched.

Fixes square#1421.
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.

Expression function runaway indentation

1 participant