Details
-
Type:
Bug
-
Status:
Closed
-
Priority:
Major
-
Resolution: Fixed
-
Affects Version/s: JRuby 1.5.1
-
Fix Version/s: JRuby 1.6RC2
-
Component/s: Ruby 1.9.2, RubySpec, Standard Library
-
Labels:None
-
Number of attachments :
Description
require 'delegate'
class MyDelegator < Delegator
attr_reader :__getobj__
def __setobj__(o)
@__getobj__ = o
end
end
d = MyDelegator.new(10)
d.freeze ## fails HERE
An attempt to execute the example above leads to:
jruby --1.9 deleg.rb
org/jruby/RubyObject$i_method_0_0$RUBYINVOKER$freeze.gen:65535:in `call': java.lang.ClassCastException: org.jruby.RubyBasicObject
cannot be cast to org.jruby.RubyObject
from JavaMethod.java:836:in `call'
from JavaMethod.java:642:in `call'
from SuperCallSite.java:286:in `cacheAndCall'
from SuperCallSite.java:70:in `callBlock'
from SuperCallSite.java:75:in `call'
from ZSuperNode.java:100:in `interpret'
from NewlineNode.java:104:in `interpret'
from BlockNode.java:71:in `interpret'
from InterpretedMethod.java:139:in `call'
from CachingCallSite.java:293:in `cacheAndCall'
from CachingCallSite.java:112:in `call'
from CallNoArgNode.java:61:in `interpret'
from NewlineNode.java:104:in `interpret'
from BlockNode.java:71:in `interpret'
from RootNode.java:129:in `interpret'
from Ruby.java:707:in `runInterpreter'
from Ruby.java:568:in `runNormally'
from Ruby.java:410:in `runFromMain'
from Main.java:286:in `run'
from Main.java:128:in `run'
from Main.java:97:in `main'
This also causes LOTS of new rubyspec failures for Delegate library.
Issue Links
- is duplicated by
-
JRUBY-5366
jruby 1.6 RC1 ruby 1.9: org.jruby.RubyBasicObject cannot be cast to org.jruby.RubyObject
-
I can't find a good solution for this, perhaps you can bump into something. The problem is that freeze and other methods are declared into RubyObject but they are also public methods of BasicObject. So we generate this java source for the Object class:
javaMethod = new org.jruby.RubyObject$i_method_0_0$RUBYINVOKER$freeze(cls, Visibility.PUBLIC); populateMethod(javaMethod, 0, "freeze", false, CallConfiguration.FrameNoneScopeNone); javaMethod.setNativeCall(org.jruby.RubyObject.class, "freeze", org.jruby.runtime.builtin.IRubyObject.class, new Class[] {org.jruby.runtime.ThreadContext.class}, false); cls.addMethodAtBootTimeOnly("freeze", javaMethod);But the method 'freeze' can be called from BasicObject:
But we can't move the freeze methods and the others to RubyBasicObject because BasicObject just includes those instance methods:
So, how we can generate something like this and don't include the methods into the BasicObject instance?
javaMethod = new org.jruby.RubyBasicObject$i_method_0_0$RUBYINVOKER$freeze(cls, Visibility.PUBLIC); populateMethod(javaMethod, 0, "freeze", false, CallConfiguration.FrameNoneScopeNone); javaMethod.setNativeCall(org.jruby.RubyObject.class, "freeze", org.jruby.runtime.builtin.IRubyObject.class, new Class[] {org.jruby.runtime.ThreadContext.class}, false); cls.addMethodAtBootTimeOnly("freeze", javaMethod);