prepending to the singleton class of a module breaks instance_method #4477

Closed
doudou opened this Issue Feb 6, 2017 · 2 comments

Comments

Projects
None yet
2 participants
@doudou

doudou commented Feb 6, 2017

Environment

jruby 9.1.7.0 (2.3.1) 2017-01-11 68056ae Java HotSpot(TM) 64-Bit Server VM 25.121-b13 on 1.8.0_121-b13 +jit [linux-x86_64]

Ubuntu 16.04 LTS, jruby installed from rbenv with no special flags.

Expected Behavior

I'm the maintainer of flexmock, and during some of the partial mock operations, flexmock prepends to the singleton class of the object that is being mocked. It also stores the original instance method before mocking it so as to be able to call it as part of the mock process. On both MRI and JRuby, this works fine for plain objects. However, when the object is itself a module, it works on MRI but fails on JRuby

The problem can be reproduced with:

module Base
    def setup_submodel; end
end
module P; end

module M
    extend Base
    class << self
        prepend P
    end
end

m = M.singleton_class.instance_method(:setup_submodel)
m.bind(M).call

MRI executes it without any problem, while JRuby fails with

TypeError: bind argument must be an instance of #<Class:0x8646db9>
    bind at org/jruby/RubyUnboundMethod.java:105
  <main> at jruby_prepend_bind_bug.rb:17
@doudou

This comment has been minimized.

Show comment
Hide comment
@doudou

doudou Feb 6, 2017

The problem seems to have been introduced between jruby 9.1.5.0 and 9.1.6.0

doudou commented Feb 6, 2017

The problem seems to have been introduced between jruby 9.1.5.0 and 9.1.6.0

@headius headius added this to the JRuby 9.1.8.0 milestone Feb 8, 2017

@headius headius added the core label Feb 8, 2017

@headius

This comment has been minimized.

Show comment
Hide comment
@headius

headius Mar 2, 2017

Member

Works ok with a plain class and module, so it's something specific to singleton/meta classes.

Member

headius commented Mar 2, 2017

Works ok with a plain class and module, so it's something specific to singleton/meta classes.

headius added a commit to headius/jruby that referenced this issue Mar 3, 2017

@headius headius closed this in #4521 Mar 3, 2017

headius added a commit that referenced this issue Mar 3, 2017

Merge pull request #4521 from headius/fix-4477
Use actual impl module to test bindability. Fixes #4477.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment