Skip to content

Unable to use UnboundMethod referencing super with define_singleton_method #3869

@saturnflyer

Description

@saturnflyer

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:

https://github.com/saturnflyer/behavioral/blob/00dae0f871ac921b77983f1535276c375f0baaa8/lib/behavioral.rb

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)

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions