Skip to content

fix: preserve leading nil in stab clause body#120

Merged
mhanberg merged 1 commit intoelixir-tools:mainfrom
mkaput:pr/00034aee-leading-nil-stab
Mar 4, 2026
Merged

fix: preserve leading nil in stab clause body#120
mhanberg merged 1 commit intoelixir-tools:mainfrom
mkaput:pr/00034aee-leading-nil-stab

Conversation

@mkaput
Copy link
Contributor

@mkaput mkaput commented Feb 20, 2026

A -> clause body can begin with a semicolon token after optional newlines, and that semicolon represents an implicit leading nil expression in the clause rhs.

The previous detection logic did not recognize the -> \n;expr shape reliably, so the resulting AST dropped that leading nil and diverged from Code.string_to_quoted/2 output in with ... else clauses.

This change detects the leading semicolon by peeking past end-of-line trivia before consuming clause eoe tokens, preserving the expected rhs shape.

A regression assertion was added to property test regression cases for with x <- 1 do :ok else _ -> \n;a end to prevent this AST mismatch from returning.

fix #113

A -> clause body can begin with a semicolon token after optional newlines, and that semicolon represents an implicit leading nil expression in the clause rhs.

The previous detection logic did not recognize the `-> \n;expr` shape reliably, so the resulting AST dropped that leading nil and diverged from Code.string_to_quoted/2 output in with ... else clauses.

This change detects the leading semicolon by peeking past end-of-line trivia before consuming clause eoe tokens, preserving the expected rhs shape.

A regression assertion was added to `property test regression cases` for `with x <- 1 do :ok else _ -> \n;a end` to prevent this AST mismatch from returning.

fix elixir-tools#113
@mhanberg mhanberg force-pushed the pr/00034aee-leading-nil-stab branch from a5eaa16 to a26a341 Compare March 4, 2026 02:42
@mhanberg mhanberg merged commit f0a79a0 into elixir-tools:main Mar 4, 2026
37 checks passed
mhanberg pushed a commit that referenced this pull request Mar 4, 2026
🤖 I have created a release *beep* *boop*
---


##
[0.3.8](v0.3.7...v0.3.8)
(2026-03-04)


### Bug Fixes

* handle ellipsis before &lt;-, ::, and when
([#114](#114))
([221fe49](221fe49))
* parse newline ternary continuation after ellipsis
([#115](#115))
([708da64](708da64))
* preserve fn newline metadata after semicolons
([#112](#112))
([52099ff](52099ff))
* preserve leading nil in stab clause body
([#120](#120))
([f0a79a0](f0a79a0)),
closes [#113](#113)

---
This PR was generated with [Release
Please](https://github.com/googleapis/release-please). See
[documentation](https://github.com/googleapis/release-please#release-please).

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
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.

with x <- 1 do :ok else _ -> \n;a end

2 participants