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

Fixnum instance variable behaviour incorrect #2255

Closed
chrisseaton opened this issue Nov 29, 2014 · 4 comments
Closed

Fixnum instance variable behaviour incorrect #2255

chrisseaton opened this issue Nov 29, 2014 · 4 comments

Comments

@chrisseaton
Copy link
Contributor

@chrisseaton chrisseaton commented Nov 29, 2014

JRuby seems to let you set instance variables on Fixnum, where in MRI this is an error. Can be demonstrated with both instance_eval and normal methods.

$ ~/.rbenv/versions/2.2.0-preview2/bin/ruby -e '14.instance_eval { p @foo = 14 }'
-e:1:in `block in <main>': can't modify frozen Fixnum (RuntimeError)
  from -e:1:in `instance_eval'
  from -e:1:in `<main>'

$ ~/.rbenv/versions/jruby-1.7.16/bin/ruby -e '14.instance_eval { p @foo = 14 }'
14

$ bin/jruby -e '14.instance_eval { p @foo = 14 }'
14

$ cat ../test.rb 
def Fixnum
  def write
    @foo = 14
  end
end
p 14.write

$ ~/.rbenv/versions/2.2.0-preview2/bin/ruby ../test.rb 
../test.rb:3:in `write': can't modify frozen Fixnum (RuntimeError)
  from ../test.rb:7:in `<main>'

$ ~/.rbenv/versions/jruby-1.7.16/bin/ruby ../test.rb 
14

$ bin/jruby ../test.rb 
14
@enebo enebo added this to the JRuby 9.0.0.0 milestone Dec 1, 2014
@enebo
Copy link
Member

@enebo enebo commented Dec 1, 2014

Marking this for 9k since Ruby 2.0+ added this behavioral change.

@lumeet
Copy link
Contributor

@lumeet lumeet commented Dec 21, 2014

I ended up looking at this. It's regression from 9585c81, RubyBasicObject#ensureInstanceVariablesSettable now always accepts variables when isImmediate returns true. So, this applies to symbols, booleans and nils, as well. I suppose the change was made because of a bug in Marshal#load when handling complex symbols. It makes me think that the original issue should be fixed in the context of unmarshaling instead of basic object. Couldn't find any neat solution. though. Too many changes required in variable accessors or thereabouts made me a bit fearful. ;(

@enebo enebo removed this from the JRuby 9.0.0.0 milestone Jul 14, 2015
@enebo enebo removed this from the JRuby 9.0.0.0 milestone Jul 14, 2015
@chrisseaton
Copy link
Contributor Author

@chrisseaton chrisseaton commented Dec 27, 2019

Closing due to inactivity.

@enebo enebo added this to the JRuby 9.2.10.0 milestone Dec 28, 2019
@enebo
Copy link
Member

@enebo enebo commented Dec 28, 2019

For posterity JRuby 9.2.10.0 is working properly. We no doubt fixed this at some point in the past without resolving this particular issue. Marking against next milestone in case anyone else was following along on this will know it has been resolved.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants