Automatically promote constants to namespaces#505
Conversation
This stack of pull requests is managed by Graphite. Learn more about stacking. |
236f30f to
f4dc87f
Compare
f4dc87f to
f71cd5b
Compare
f71cd5b to
3b13abf
Compare
3b13abf to
1e44ea9
Compare
1e44ea9 to
4c602d8
Compare
st0012
left a comment
There was a problem hiding this comment.
I think it may be possible to further extend this approach in follow up PRs to also promote cases like:
Foo = some_method do
include Bar # doing mixing stuff
def baz; end # defining methods
endIn this PR, we already promote Foo when it's reopened for those operations, so IMO it makes sense to promote the above cases too. And it'd be a foundation for a basic DSL support.
@vinistock and I talked about this idea yesterday but it's not confirmed whether it'd be feasible/ideal or not.
Other than this, I think the PR is good to merge so we can index Core again.
4c602d8 to
4d2f41e
Compare
|
I added a test to document the current behaviour. Meta-programmed namespaces don't get auto promoted at the moment. That would involve inspecting to see if there are members inside, which is a bit much for this PR, but might be an avenue we want to explore for DSL handling. |
4d2f41e to
5666886
Compare

This PR does two main things:
Although we can't provide first class features when there's meta-programming, we absolutely cannot crash. Consider these examples (or the ones added as tests):
This PR takes two strategies to prevent crashing completely in these scenarios:
By auto-promoting, we correctly handle ancestors and constant resolution for
Const. Of course, there's a concession being made to the user here: we trust that they didn't make a mistake by making an incompatible re-opening (i.e.: it was a module, then gets reopened as a class).