Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: jruby/jruby
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: 2d5e038c692e
Choose a base ref
...
head repository: jruby/jruby
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: 30594f467c2f
Choose a head ref
  • 2 commits
  • 2 files changed
  • 1 contributor

Commits on Aug 16, 2016

  1. Copy the full SHA
    c5028dc View commit details
  2. Define module_function singleton method as proper clone.

    We used to use WrapperMethod to carry the alternate implementation
    class and visibility for the singleton method. That type of method
    does not pass impl class through to the contained method, which
    resulted in the eventual "implementer search" from trying to find
    an implementer of the module, rather than doing a simple
    superclass of the module's singleton. Because the module is
    obviously not found in its own singleton class's hierarchy, that
    search produced null, and we blindly proceeded to attempt to call
    the super method on null.
    
    This now uses a proper clone of the original method for the
    singleton version, with its own implClass that propagates into
    the implementer search, and super works properly up the singleton
    hierarchy.
    
    Fixes #3708.
    headius committed Aug 16, 2016
    Copy the full SHA
    30594f4 View commit details
Showing with 22 additions and 1 deletion.
  1. +4 −1 core/src/main/java/org/jruby/runtime/Helpers.java
  2. +18 −0 spec/ruby/core/module/module_function_spec.rb
5 changes: 4 additions & 1 deletion core/src/main/java/org/jruby/runtime/Helpers.java
Original file line number Diff line number Diff line change
@@ -1794,7 +1794,10 @@ public static RubySymbol addInstanceMethod(RubyModule containingClass, String na
}

private static void addModuleMethod(RubyModule containingClass, String name, DynamicMethod method, ThreadContext context, RubySymbol sym) {
containingClass.getSingletonClass().addMethod(name, new WrapperMethod(containingClass.getSingletonClass(), method, Visibility.PUBLIC));
DynamicMethod singletonMethod = method.dup();
singletonMethod.setImplementationClass(containingClass.getSingletonClass());
singletonMethod.setVisibility(Visibility.PUBLIC);
containingClass.getSingletonClass().addMethod(name, singletonMethod);
containingClass.callMethod(context, "singleton_method_added", sym);
}

18 changes: 18 additions & 0 deletions spec/ruby/core/module/module_function_spec.rb
Original file line number Diff line number Diff line change
@@ -128,6 +128,24 @@ def test2() end
end
m.respond_to?(:require).should be_true
end

it "creates Module methods that super up the singleton class of the module" do
super_m = Module.new do
def foo
"super_m"
end
end

m = Module.new do
extend super_m
module_function
def foo
["m", super]
end
end

m.foo.should == ["m", "super_m"]
end
end

describe "Module#module_function as a toggle (no arguments) in a Module body" do