natalie-lang / natalie

a work-in-progress Ruby compiler, written in Ruby and C++
https://natalie-lang.org
MIT License
938 stars 63 forks source link

Scoping when reopening a toplevel constant #2269

Open herwinw opened 1 day ago

herwinw commented 1 day ago

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.

seven1m commented 1 day ago

Wow