Project

General

Profile

Actions

Bug #20948

open

Constant references incorrectly cached in `module (expr)::Foo`

Added by mame (Yusuke Endoh) 6 days ago. Updated 4 days ago.

Status:
Assigned
Target version:
-
[ruby-core:120213]

Description

module M1
  module Foo
    X = 1
  end
end

module M2
  module Foo
    X = 2
  end
end

[M1, M2].each do
  module it::Foo
    p X #=> expected: prints "1" then "2"; actual: prints "1" twice
  end
end

To be honest, I don't think it's worth slowing down the processor for this, but I create a ticket since I discovered it and since ko1 seemed to have a bit of an idea of how to solve it.

Updated by Eregon (Benoit Daloze) 4 days ago ยท Edited

There used to be a similar bug a while ago and IIRC some specs were added, @ko1 (Koichi Sasada) maybe you remember it and could link that ticket here?

I think it was constants inside class << expr though, not inside module expr::Foo.

(FWIW, it's already 1\n2 on TruffleRuby which detects this case as non-static constant scope:

$ ruby --experimental-options --ruby.constant-dynamic-lookup-log c.rb
...
[ruby] INFO: start dynamic constant lookup at c.rb:14
[ruby] INFO: dynamic constant lookup at c.rb:15
1
2

)

Actions

Also available in: Atom PDF

Like0
Like0