Skip to content

Commit

Permalink
[Truffle] Fix message when calling protected methods.
Browse files Browse the repository at this point in the history
  • Loading branch information
eregon committed Sep 6, 2016
1 parent df803e0 commit 4d0f7d3
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 5 deletions.
Expand Up @@ -315,11 +315,16 @@ private Object methodMissing(Object self, DynamicObject nameObject, Object[] arg
private DynamicObject buildMethodMissingException(Object self, DynamicObject nameObject, Object[] args, DynamicObject block) {
final String name = nameObject.toString();
final FrameInstance relevantCallerFrame = getRelevantCallerFrame();
Visibility visibility;

if (lastCallWasSuper(relevantCallerFrame)) {
return coreExceptions().noSuperMethodError(name, self, args, this);
} else if (lastCallWasCallingPrivateMethod(self, name)) {
return coreExceptions().privateMethodError(name, self, args, this);
} else if ((visibility = lastCallWasCallingPrivateOrProtectedMethod(self, name)) != null) {
if (visibility.isPrivate()) {
return coreExceptions().privateMethodError(name, self, args, this);
} else {
return coreExceptions().protectedMethodError(name, self, args, this);
}
} else if (lastCallWasVCall(relevantCallerFrame)) {
return coreExceptions().nameErrorUndefinedLocalVariableOrMethod(name, self, this);
} else {
Expand Down Expand Up @@ -360,13 +365,13 @@ private boolean lastCallWasSuper(FrameInstance callerFrame) {
* See {@link org.jruby.truffle.language.dispatch.DispatchNode#lookup}.
* The only way to fail if method is not null and not undefined is visibility.
*/
private boolean lastCallWasCallingPrivateMethod(Object self, String name) {
private Visibility lastCallWasCallingPrivateOrProtectedMethod(Object self, String name) {
final InternalMethod method = ModuleOperations.lookupMethod(coreLibrary().getMetaClass(self), name);
if (method != null && !method.isUndefined()) {
assert method.getVisibility().isPrivate() || method.getVisibility().isProtected();
return true;
return method.getVisibility();
}
return false;
return null;
}

private boolean lastCallWasVCall(FrameInstance callerFrame) {
Expand Down
Expand Up @@ -583,6 +583,12 @@ public DynamicObject privateMethodError(String name, Object self, Object[] args,
return noMethodError(StringUtils.format("private method `%s' called for %s", name, className), self, name, args, currentNode);
}

@TruffleBoundary
public DynamicObject protectedMethodError(String name, Object self, Object[] args, Node currentNode) {
String className = Layouts.MODULE.getFields(context.getCoreLibrary().getLogicalClass(self)).getName();
return noMethodError(StringUtils.format("protected method `%s' called for %s", name, className), self, name, args, currentNode);
}

// LoadError

@TruffleBoundary
Expand Down

0 comments on commit 4d0f7d3

Please sign in to comment.