Move conditional from Region to the CompoundStatement pin itself - #58
Merged
apiology merged 1 commit intoAug 14, 2026
Merged
Conversation
Region#conditional was a separate boolean threaded alongside compound_statement, requiring every node processor to pass both in lockstep (e.g. block_node.rb: compound_statement: block_pin, conditional: true). Keeping two parallel values in sync at every call site is exactly the kind of duplication this refactor set out to remove, and it's the shape of bug that broke Block handling mid-refactor (definite briefly, incorrectly, derived from compound_statement.is_a?(Closure), which is true for Block despite a block body running zero or many times). conditional is now a constructor attribute on Pin::CompoundStatement itself, set once where each construct is built (Pin::Block.new(..., conditional: true), Pin::Method.new(...) defaulting false), so there's only one thing to get right per site instead of two. It can't be a class-level constant: the bare Pin::CompoundStatement class is used both for an if's own condition (never conditional) and for then/else/rhs/rescue bodies (always conditional) - same class, different instances, different answers - so it stays an instance attribute, same as closure:/compound_statement: already are. lvasgn_node.rb's definite computation becomes a single-hop read: `!region.compound_statement.conditional`, no separate Region field. Pin::CompoundStatement#combine_with merges the new attribute via `choose`, since two versions of the same construct should already agree on it. Verified: full suite (1638 examples, 0 failures), typecheck self-check diffed clean against the prior baseline (587 problems, unchanged), rubocop clean on touched files. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01YbhZvdCv7xdziXyKJiPuGk
apiology
merged commit Aug 14, 2026
9fe7637
into
fix-1250-parameter-reassignment-typing
27 of 28 checks passed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Follow-up to castwide#1282 (via #57), stacked on the same head branch.
Summary
Region#conditionalwas a separate boolean threaded alongsidecompound_statement, requiring every node processor to pass both in lockstep (e.g.block_node.rb:compound_statement: block_pin, conditional: true). Keeping two parallel values in sync at every call site is exactly the kind of duplication #57 set out to remove, and it's the shape of bug that broke Block handling mid-refactor there (definitewas briefly, incorrectly, derived fromcompound_statement.is_a?(Closure), which is true forBlockdespite a block body running zero or many times).conditionalis now a constructor attribute onPin::CompoundStatementitself, set once where each construct is built (Pin::Block.new(..., conditional: true),Pin::Method.new(...)defaultingfalse), so there's only one thing to get right per site instead of two.It can't be a class-level constant: the bare
Pin::CompoundStatementclass is used both for anif's own condition (never conditional) and for then/else/rhs/rescue bodies (always conditional) - same class, different instances, different answers - so it stays an instance attribute, same asclosure:/compound_statement:already are.lvasgn_node.rb'sdefinitecomputation becomes a single-hop read:!region.compound_statement.conditional, no separateRegionfield.Pin::CompoundStatement#combine_withmerges the new attribute viachoose, since two versions of the same construct should already agree on it.Test plan
bundle exec rspec spec/- 1638 examples, 0 failuresbundle exec solargraph typecheck --level strong- diffed clean against the prior baseline (587 problems, unchanged)bundle exec rubocop- clean on touched filesCo-Authored-By: Claude Sonnet 5 noreply@anthropic.com