Skip to content


Fix edge case in findMethodInstanceContainer codeo
Browse files Browse the repository at this point in the history
* Looks like we can have scenarios where 'self' for a closure
  executed in a module_eval context need not be the module
  but a different object. In that case, we still need to add
  the method to self => we need to get its metaclass first.

* This fixes crasher in this case:

require "minitest/autorun"

describe "A" do
  it "should do something" do
    def foo
  • Loading branch information
subbuss committed Apr 21, 2015
1 parent e5e5198 commit c2f66f2
Showing 1 changed file with 8 additions and 1 deletion.
Expand Up @@ -735,7 +735,14 @@ public static RubyModule findInstanceMethodContainer(ThreadContext context, Dyna
for (DynamicScope ds = currDynScope; ds != null; ) {
IRScopeType scopeType = ds.getStaticScope().getScopeType();
switch (ds.getEvalType()) {
case MODULE_EVAL : return (RubyModule) self;
// The most common use case here is where :
// - a method is defined inside a closure
// that is nested inside a module_eval.
// here self = the module
// - in the rare case where it is not (looks like it can
// happen in some testing frameworks), we have to add
// the method to self itself => its metaclass.
case MODULE_EVAL : return self instanceof RubyModule ? (RubyModule) self : self.getMetaClass();
case INSTANCE_EVAL: return self.getSingletonClass();
case BINDING_EVAL : ds = ds.getParentScope(); break;
case NONE:
Expand Down

0 comments on commit c2f66f2

Please sign in to comment.