Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
[Truffle] Fix method search of Module#alias_method and public/protect…
…ed/private.

* So spec/ruby/core/module/fixtures/classes.rb can now be required without errors.
  • Loading branch information
eregon committed Oct 22, 2014
1 parent ea30db2 commit cd315fa
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 2 deletions.
Expand Up @@ -830,6 +830,7 @@ public PublicNode(PublicNode prev) {
public RubyModule doPublic(RubyModule module, Object... args) {
notDesignedForCompilation();

module.visibilityMethod(this, args, Visibility.PUBLIC);
module.visibilityMethod(this, args, Visibility.PUBLIC);
return module;
}
Expand Down
19 changes: 17 additions & 2 deletions core/src/main/java/org/jruby/truffle/runtime/core/RubyModule.java
Expand Up @@ -257,10 +257,25 @@ public void undefMethod(RubyNode currentNode, RubyMethod method) {
addMethod(currentNode, method.undefined());
}

/**
* Also searches on Object for modules.
* Used for alias_method, visibility changes, etc.
*/
private RubyMethod deepMethodSearch(String name) {
RubyMethod method = ModuleOperations.lookupMethod(this, name);

// Also search on Object if we are a Module. JRuby calls it deepMethodSearch().
if (method == null && !(this instanceof RubyClass)) { // TODO: handle undefined methods
method = ModuleOperations.lookupMethod(context.getCoreLibrary().getObjectClass(), name);
}

return method;
}

public void alias(RubyNode currentNode, String newName, String oldName) {
RubyNode.notDesignedForCompilation();

final RubyMethod method = ModuleOperations.lookupMethod(this, oldName);
RubyMethod method = deepMethodSearch(oldName);

if (method == null) {
CompilerDirectives.transferToInterpreter();
Expand Down Expand Up @@ -365,7 +380,7 @@ public void visibilityMethod(RubyNode currentNode, Object[] arguments, Visibilit
throw new UnsupportedOperationException();
}

final RubyMethod method = ModuleOperations.lookupMethod(this, methodName);
final RubyMethod method = deepMethodSearch(methodName);

if (method == null) {
throw new RuntimeException("Couldn't find method " + arg.toString());
Expand Down

0 comments on commit cd315fa

Please sign in to comment.