Stop regenerating all value constants for reopened types #1385
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.
Motivation
Fixes #1326
Implementation
When we are generating value constants (i.e. constants that have a value that is not a module), we didn't have a good way to filter them based on where they were defined, since we couldn't ask them before.
However, since Ruby 2.7, we have access to
const_source_location
so we can check to see if a value constant has been defined by the current gem or not. So the implementation uses that.Tests
Updated existing tests to test for this specific case where the
bar
gem is reopening a constant defined by thefoo
gem and adds a value constant under it. The expectation is that only the subconstant added inbar
gem is generated inbar.rbi
and none of the other subconstants defined infoo
.I also tested this against Core and it works without problems (and gets rid of a lot of unnecessary constant definitions on gem RBI files).