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

eval treats all method definitions as public #2384

Closed
nirvdrum opened this issue Dec 29, 2014 · 2 comments
Closed

eval treats all method definitions as public #2384

nirvdrum opened this issue Dec 29, 2014 · 2 comments

Comments

@nirvdrum
Copy link
Contributor

@nirvdrum nirvdrum commented Dec 29, 2014

It looks like JRuby doesn't correctly keep track of method visibility for those defined in eval.

MRI:

$ ruby -v
ruby 2.2.0p0 (2014-12-25 revision 49005) [x86_64-linux

$ ruby -e "cls = Class.new; cls.module_eval { eval('def x; :x; end') }; p cls.new.x"
:x

$ ruby -e "cls = Class.new; cls.module_eval { eval('private; def x; :x; end') }; p cls.new.x"
-e:1:in `<main>': private method `x' called for #<#<Class:0x007f9bac9dc818>:0x007f9bac9dc408> (NoMethodError)

$ ruby -e "cls = Class.new; cls.module_eval { eval('private def x; :x; end') }; p cls.new.x"
-e:1:in `<main>': private method `x' called for #<#<Class:0x007f1c997a4920>:0x007f1c997a4538> (NoMethodError)

JRuby:

$ bin/jruby -v
jruby 9.0.0.0-SNAPSHOT (2.2.0p0) 2014-12-29 cce55de Java HotSpot(TM) 64-Bit Server VM 24.72-b04 on 1.7.0_72-b14 +jit [linux-amd64]

$ bin/jruby -e "cls = Class.new; cls.module_eval { eval('def x; :x; end') }; p cls.new.x"
:x

$ bin/jruby -e "cls = Class.new; cls.module_eval { eval('private; def x; :x; end') }; p cls.new.x"
:x

$ bin/jruby -e "cls = Class.new; cls.module_eval { eval('private def x; :x; end') }; p cls.new.x"
:x
@nirvdrum nirvdrum added this to the JRuby 9.0.0.0 milestone Dec 30, 2014
@lumeet
Copy link
Contributor

@lumeet lumeet commented Jan 6, 2015

I don't know if I'm just dreaming or what but I think there are no private methods at all on master.

Just a couple of examples:

$ bin/jruby -e "class Klass; def x; :x; end; private :x; end; p Klass.new.x"
:x

$ bin/jruby -e "String.fail 'Oh no'"
RuntimeError: Oh no

bin/jruby -e "String.remove_method :to_s"

@headius
Copy link
Member

@headius headius commented Jan 6, 2015

I suspect this is a simple problem of the JIT not enforcing visibiity:

~/projects/jruby $ jruby -e "String.remove_method :to_s"

~/projects/jruby $ jruby -X-C -e "String.remove_method :to_s"
NoMethodError: undefined method `remove_method' for String:Class
  method_missing at org/jruby/RubyBasicObject.java:1600
          (root) at -e:1

@headius headius removed this from the JRuby 9.0.0.0 milestone Jan 16, 2015
@headius headius added this to the JRuby 9.0.0.0-pre1 milestone Jan 16, 2015
@headius headius added this to the JRuby 9.0.0.0-pre1 milestone Jan 16, 2015
@headius headius removed this from the JRuby 9.0.0.0 milestone Jan 16, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants