Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Scoping when reopening a toplevel constant #2269

Open
herwinw opened this issue Oct 25, 2024 · 2 comments
Open

Scoping when reopening a toplevel constant #2269

herwinw opened this issue Oct 25, 2024 · 2 comments
Labels
bug Something isn't working

Comments

@herwinw
Copy link
Member

herwinw commented Oct 25, 2024

A piece of code because nobody will understand this title:

module Foo
  module Bar
    class ::Object
      Bar
    end
  end
end

This works fine in MRI, where it uses the Foo::Bar constant. In Natalie, it tries to look up ::Bar and fails.

This structure is used in the Nesting fixture in spec/core/module, which causes all the module specs in the nightly test to fail (we'd also need to implement Module.nesting, but we could just use a stub method).

Look up the exact rules for this, what happens when there is a toplevel Bar module as well? This must be documented somewhere.

@herwinw herwinw added the bug Something isn't working label Oct 25, 2024
@seven1m
Copy link
Member

seven1m commented Oct 25, 2024

Wow

@seven1m
Copy link
Member

seven1m commented Dec 20, 2024

I keep pondering this ... it bothers me. We do most of our namespace resolution stuff using the self and walking up the hierarchy of owner chains. But now, with this example, we cannot store Bar as an owner of ::Object, so we would need another clue to look for Bar.

Maybe we could pass an additional argument into ModuleObject::eval_body that is the self at time of definition. 🤔

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants