Skip to content

Prepending a module hides module's constants #6271

@marcandre

Description

@marcandre
module E; end

module Foo
  FOO = 42
  prepend E # remove me, or change prepend => include
end

class X
  include Foo

  def m
    p FOO
  end
end

X.new.m # => should print 42. Instead:
# NameError: uninitialized constant X::FOO
# Did you mean?  Foo
#   const_missing at org/jruby/RubyModule.java:3747
#               m at bug.rb:12
#          <main> at bug.rb:16

As in the comment, if E is included instead of prepended, or not in the ancestors at all, the code works as expected. I tested in Ruby 2.7 and 2.0 just for kicks, all work.

$ ruby -v
jruby 9.2.9.0 (2.5.7) 2019-10-30 458ad3e Java HotSpot(TM) 64-Bit Server VM 9.0.1+11 on 9.0.1+11 +jit [darwin-x86_64]

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions