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

Module#included is private when called with super #3008

Closed
ahawkins opened this Issue May 31, 2015 · 4 comments

Comments

Projects
None yet
2 participants
@ahawkins
Copy link

ahawkins commented May 31, 2015

I came across this issue when trying out one of my libraries on jruby 9000 pre2. The relevant source code is here: https://github.com/Saltside/thrift-base64-ruby/blob/master/lib/thrift/base64.rb#L22-51

Note the comment about using prepend and included. The code fails on 9000.pre2 like so:

NoMethodError: private method `included' called for Thrift::Struct:Module
          included at /usr/local/bundle/gems/thrift-base64-0.1.1/lib/thrift/base64.rb:35
           include at org/jruby/RubyModule.java:2408

I could remove my work around and use included like normal, but it seems strange that a method would change scope when invoked with super.

This is easily to replicate. Clone that library and run the tests on 9000.pre2.

@headius

This comment has been minimized.

Copy link
Member

headius commented Jun 1, 2015

Interesting. Will have a look.

@headius

This comment has been minimized.

Copy link
Member

headius commented Jun 2, 2015

Simple reproduction:

module A
  def included(base)
    super
  end
end

module B
  class << self
    prepend A
  end
end

class C
  include B
end
@headius

This comment has been minimized.

Copy link
Member

headius commented Jun 2, 2015

This logic in IRRuntimeHelpers.unresolvedSuper seems to be responsible for the method_missing call. I'm not sure why we are checking prepended in this way:

        if (method.isUndefined() || (superClass.isPrepended() && (method.isImplementedBy(self.getType())))) {
            rVal = Helpers.callMethodMissing(context, self, method.getVisibility(), methodName, CallType.SUPER, args, block);
        } else {

@headius headius closed this in 3579f2e Jun 2, 2015

headius added a commit that referenced this issue Jun 2, 2015

@headius headius added this to the JRuby 9.0.0.0.rc1 milestone Jun 2, 2015

@ahawkins

This comment has been minimized.

Copy link
Author

ahawkins commented Jun 2, 2015

@headius awesome work, will verify again when RC1 is out.

headius added a commit to ruby/spec that referenced this issue Jun 3, 2015

eregon added a commit that referenced this issue Jun 3, 2015

Squashed 'spec/ruby/' changes from ac1063b..71ff5e4
71ff5e4 Remove unintended tabs in spec.
32dbc10 Method scopes default to public visibility for def.
6209f82 Add spec for prepend behavior from #3008.
1d62f36 Split the Complex#hash spec into smaller examples.
716c2f1 Remove invalid assertion in SizedQueue#enq spec.
bbd6d3b Remove the Dir glob encoding spec.
f55ce4a Cleanup __method__ and __callee__ specs.

git-subtree-dir: spec/ruby
git-subtree-split: 71ff5e4dac390e1304a9da3af99cd4b915dad467
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.