autoload resets private_constant
Is this behavior intentional?
Suppose the following file:
$ cat a/b.rb class A; B = 1; end
$ ruby -I. -e 'class A;autoload :B, "a/b.rb"; private_constant :B; end' -e 'p A::B' -e:2:in `<main>': private constant A::B referenced (NameError)
But after it got loaded,
A::B becomes public.
$ ruby -I. -e 'class A;autoload :B, "a/b.rb"; private_constant :B; B; end' -e 'p A::B' 1
Updated by jeremyevans0 (Jeremy Evans) 3 months ago
- File const-visibility-before-autoload-11055.patch const-visibility-before-autoload-11055.patch added
I doubt dropping the existing constant visibility information is intentional behavior. You can work around the current behavior by resetting
deprecate_constant inside the autoloaded file, but that leads to duplication.
Attached is a patch that will copy the constant visibility information across the autoload.