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

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

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

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

doudou opened this issue Feb 6, 2017 · 2 comments
Labels
Milestone

Comments

@doudou
Copy link

@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
Copy link
Author

@doudou 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
Copy link
Member

@headius 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
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
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

2 participants
You can’t perform that action at this time.