-
-
Notifications
You must be signed in to change notification settings - Fork 942
Description
I'm unable to transplant a method defined in a module to define a method on another object
Environment
jruby 9.1.0.0 (2.3.0) 2016-05-02 a633c63 Java HotSpot(TM) 64-Bit Server VM 25.77-b03 on 1.8.0_77-b03 +jit [darwin-x86_64]
Expected Behavior
I expect to be able to define methods on an object using define_singleton_method and instance methods from a module
Example code:
Or using this sample in an irb session should work:
class P
def name
'name'
end
end
module Mod
def name
"mod #{super}"
end
end
p = P.new
p.define_singleton_method(:name, Mod.instance_method(:name))
p.send :name #=> "mod name"Actual Behavior
NullPointerException
I'm still trying to track down the exact cause of this and will update this issue if I find the concrete trigger but for now I have failing tests at: https://travis-ci.org/saturnflyer/behavioral/jobs/128500121
I believe it has to do with using super inside an UnboundMethod used to define the singleton_class instance method.
If you remove the super call from the example code above, it works fine.
Example stack trace from the link to travis-ci above:
1) Error:
Behavioral#test_0003_allows adding multiple behavior modules at once:
Java::JavaLang::NullPointerException:
org.jruby.ir.runtime.IRRuntimeHelpers.unresolvedSuper(IRRuntimeHelpers.java:991)
org.jruby.ir.instructions.UnresolvedSuperInstr.interpret(UnresolvedSuperInstr.java:83)
org.jruby.ir.interpreter.InterpreterEngine.processCall(InterpreterEngine.java:348)
org.jruby.ir.interpreter.StartupInterpreterEngine.interpret(StartupInterpreterEngine.java:77)
org.jruby.ir.interpreter.InterpreterEngine.interpret(InterpreterEngine.java:80)
org.jruby.internal.runtime.methods.MixedModeIRMethod.INTERPRET_METHOD(MixedModeIRMethod.java:144)