Skip to content

Propagate newline from if to bodies#9355

Merged
headius merged 1 commit intojruby:jruby-10.0from
headius:if_modifier_line_fix
Apr 1, 2026
Merged

Propagate newline from if to bodies#9355
headius merged 1 commit intojruby:jruby-10.0from
headius:if_modifier_line_fix

Conversation

@headius
Copy link
Copy Markdown
Member

@headius headius commented Mar 31, 2026

This is a somewhat form-fitted fix for #9293 that only assists with line numbers of the then and else bodies of IfNode. In the linked issue, a trailing if or unless modifier will be used as the line number that an associated call gets associated with, causing stack output like from caller_locations to be incorrect. In CRuby, this newline propagation appears to be done during the reduce_nodes function, but that function has many side effects in its macro-heavy logic and an initial attempt to port it did not fix the issue in question. Instead, I just detect this specific case and propagate the newline manually.

There may be other such cases, and once we encounter those there may be a better justification for formally duplicating the newline side-effect logic from reduce_node. For now, this quick fix is probably good enough.

Fixes #9293

@headius headius added this to the JRuby 10.0.5.0 milestone Mar 31, 2026
This is a somewhat form-fitted fix for jruby#9293 that only
assists with line numbers of the then and else bodies of IfNode. In
the linked issue, a trailing `if` or `unless` modifier will be used
as the line number that an associated call gets associated with,
causing stack output like from `caller_locations` to be incorrect.
In CRuby, this newline propagation appears to be done during the
`reduce_nodes` function, but that function has many side effects
in its macro-heavy logic and an initial attempt to port it did not
fix the issue in question. Instead, I just detect this specific
case and propagate the newline manually.

There may be other such cases, and once we encounter those there
may be a better justification for formally duplicating the newline
side-effect logic from `reduce_node`. For now, this quick fix is
probably good enough.

Fixes jruby#9293
@headius headius force-pushed the if_modifier_line_fix branch from cdf17ef to 31d1685 Compare April 1, 2026 13:41
@headius headius merged commit 7679764 into jruby:jruby-10.0 Apr 1, 2026
106 of 107 checks passed
@headius headius deleted the if_modifier_line_fix branch April 1, 2026 16:06
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.

1 participant