Merge duplicate constant declarations into a union type#461
Merged
sinsoku merged 1 commit intoJun 21, 2026
Conversation
bdd119c to
23af2a2
Compare
When a constant was assigned more than once (e.g. `D = 1; D = "str"`), `Service#dump_declarations` emitted one declaration line per assignment, so the same constant appeared multiple times (`D: Integer` followed by `D: String`). Deduplicate constant writes by their static cpath so that each constant yields a single declaration, and show the union of its types (`D: (Integer | String)`) when it is assigned more than once. A single assignment keeps using the assigned value (`node.ret`) rather than the constant entity's type, so that a same-named class or module (e.g. one declared in RBS) is not mixed into the declaration; see scenario/rbs/remove-class.rb. The deduplication mirrors the existing seen_ivars/seen_cvars/seen_gvars handling in the same method. Promote scenario/known-issues/multi-const-write.rb to scenario/const/ and update scenario/variable/operator_write.rb, which previously encoded the duplicated output. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
23af2a2 to
093ecd3
Compare
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.
When a constant is assigned more than once,
Service#dump_declarationsemitted one declaration line per assignment, so
was dumped as two declarations for the same constant:
This deduplicates constant writes by their static cpath so that each
constant yields a single declaration, and shows the union of its types
when it is assigned more than once:
A single assignment keeps using the assigned value (
node.ret) ratherthan the constant entity's type, so that a same-named class or module
(e.g. one declared in RBS) is not mixed into the declaration; see
scenario/rbs/remove-class.rb, whereC = 1coexists with an RBSclass Cand the declaration is expected to stayC: Integer. Thededuplication mirrors the existing
seen_ivars/seen_cvars/seen_gvarshandling in the same method.
scenario/known-issues/multi-const-write.rbnow passes and is promotedto
scenario/const/.scenario/variable/operator_write.rbis updatedsince it previously encoded the duplicated output (
D = 0; D += 1andC::E = 0; C::E += 1now each produce a single line).All 429 tests pass (
bundle exec rake test).