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: bab8f0aafd44
Choose a base ref
...
head repository: jruby/jruby
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: b2371dd49242
Choose a head ref
  • 3 commits
  • 7 files changed
  • 1 contributor

Commits on May 27, 2016

  1. Copy the full SHA
    49d898f View commit details
  2. Ensure all formatted new{Name,NoMethod}Error callers format right.

    Several cases were formatting the string ahead of time rather
    than allowing the formatting mechanism to work. Relates to #3934.
    headius committed May 27, 2016
    Copy the full SHA
    eb7e1fc View commit details
  3. Copy the full SHA
    b2371dd View commit details
8 changes: 4 additions & 4 deletions core/src/main/java/org/jruby/Ruby.java
Original file line number Diff line number Diff line change
@@ -4066,11 +4066,11 @@ public RaiseException newNoMethodError(String message, IRubyObject recv, String
}

/**
* Construct a NoMethodError that formats its message with an sprintf format string.
*
* This is the same as {@link #newNoMethodError(String, IRubyObject, String, RubyArray)} but without
* capturing the receiver.
* Construct a NoMethodError with a pre-formatted message.
*
* @param message the pre-formatted message
* @param name the name that failed
* @param args the original arguments to the call that failed
* @return a new NoMethodError
*/
public RaiseException newNoMethodError(String message, String name, IRubyObject args) {
6 changes: 3 additions & 3 deletions core/src/main/java/org/jruby/RubyBasicObject.java
Original file line number Diff line number Diff line change
@@ -2792,7 +2792,7 @@ public IRubyObject remove_instance_variable(ThreadContext context, IRubyObject n
if ((value = (IRubyObject)variableTableRemove(validateInstanceVariable(name, name.asJavaString()))) != null) {
return value;
}
throw context.runtime.newNameError("instance variable " + name.asJavaString() + " not defined", this, name);
throw context.runtime.newNameError("instance variable %1$s not defined", this, name);
}

/** rb_obj_instance_variables
@@ -2885,13 +2885,13 @@ protected static int nonFixnumHashCode(IRubyObject hashValue) {
protected String validateInstanceVariable(String name) {
if (IdUtil.isValidInstanceVariableName(name)) return name;

throw getRuntime().newNameError("`" + name + "' is not allowable as an instance variable name", this, name);
throw getRuntime().newNameError("`%1$s' is not allowable as an instance variable name", this, name);
}

protected String validateInstanceVariable(IRubyObject nameObj, String name) {
if (IdUtil.isValidInstanceVariableName(name)) return name;

throw getRuntime().newNameError("`" + name + "' is not allowable as an instance variable name", this, nameObj);
throw getRuntime().newNameError("`%1$s' is not allowable as an instance variable name", this, nameObj);
}

/**
10 changes: 5 additions & 5 deletions core/src/main/java/org/jruby/RubyKernel.java
Original file line number Diff line number Diff line change
@@ -246,16 +246,16 @@ private static String getMethodMissingFormat(Visibility visibility, CallType cal
String format = null;

if (visibility == PRIVATE) {
format = "private method `%s' called for %s";
format = "private method `%1$s' called for %2$s";
} else if (visibility == PROTECTED) {
format = "protected method `%s' called for %s";
format = "protected method `%1$s' called for %2$s";
} else if (callType == CallType.VARIABLE) {
format = "undefined local variable or method `%s' for %s";
format = "undefined local variable or method `%1$s' for %2$s";
} else if (callType == CallType.SUPER) {
format = "super: no superclass method `%s'";
format = "super: no superclass method `%1$s'";
}

if (format == null) format = "undefined method `%s' for %s";
if (format == null) format = "undefined method `%1$s' for %2$s";

return format;
}
8 changes: 4 additions & 4 deletions core/src/main/java/org/jruby/RubyModule.java
Original file line number Diff line number Diff line change
@@ -3503,7 +3503,7 @@ public IRubyObject getClassVar(String name) {
IRubyObject value = getClassVarQuiet(name);

if (value == null) {
throw getRuntime().newNameError("uninitialized class variable %s in %s", this, name);
throw getRuntime().newNameError("uninitialized class variable %1$s in %2$s", this, name);
}

return value;
@@ -3513,7 +3513,7 @@ public IRubyObject getClassVar(IRubyObject nameObject, String name) {
IRubyObject value = getClassVarQuiet(name);

if (value == null) {
throw getRuntime().newNameError("uninitialized class variable %s in %s", this, nameObject);
throw getRuntime().newNameError("uninitialized class variable %1$s in %2$s", this, nameObject);
}

return value;
@@ -4090,14 +4090,14 @@ protected final String validateClassVariable(String name) {
if (IdUtil.isValidClassVariableName(name)) {
return name;
}
throw getRuntime().newNameError("`" + name + "' is not allowed as a class variable name", this, name);
throw getRuntime().newNameError("`%1$s' is not allowed as a class variable name", this, name);
}

protected final String validateClassVariable(IRubyObject nameObj, String name) {
if (IdUtil.isValidClassVariableName(name)) {
return name;
}
throw getRuntime().newNameError("`" + name + "' is not allowed as a class variable name", this, nameObj);
throw getRuntime().newNameError("`%1$s' is not allowed as a class variable name", this, nameObj);
}

protected final void ensureClassVariablesSettable() {
12 changes: 6 additions & 6 deletions core/src/main/java/org/jruby/RubyStruct.java
Original file line number Diff line number Diff line change
@@ -63,9 +63,9 @@
*/
@JRubyClass(name="Struct")
public class RubyStruct extends RubyObject {
public static final String NO_MEMBER_IN_STRUCT = "no member '%s' in struct";
public static final String IDENTIFIER_NEEDS_TO_BE_CONSTANT = "identifier %s needs to be constant";
public static final String UNINITIALIZED_CONSTANT = "uninitialized constant %s";
public static final String NO_MEMBER_IN_STRUCT = "no member '%1$s' in struct";
public static final String IDENTIFIER_NEEDS_TO_BE_CONSTANT = "identifier %1$s needs to be constant";
public static final String UNINITIALIZED_CONSTANT = "uninitialized constant %1$s";
private final IRubyObject[] values;

/**
@@ -468,7 +468,7 @@ public IRubyObject set(IRubyObject value, int index) {
return values[index] = value;
}

private RaiseException notStructMemberError(String name) {
private RaiseException notStructMemberError(IRubyObject name) {
return getRuntime().newNameError(NO_MEMBER_IN_STRUCT, this, name);
}

@@ -655,7 +655,7 @@ private IRubyObject arefImpl(IRubyObject key, final boolean nilOnNoMember) {
final IRubyObject value = getByName(name);
if ( value == null ) {
if ( nilOnNoMember ) return getRuntime().getNil();
throw notStructMemberError(name);
throw notStructMemberError(key);
}
return value;
}
@@ -680,7 +680,7 @@ public IRubyObject aset(IRubyObject key, IRubyObject value) {
if (key instanceof RubyString || key instanceof RubySymbol) {
final String name = key.asJavaString();
final IRubyObject val = setByName(name, value);
if ( val == null ) throw notStructMemberError(name);
if ( val == null ) throw notStructMemberError(key);
return value;
}

13 changes: 1 addition & 12 deletions core/src/main/java/org/jruby/ir/runtime/IRRuntimeHelpers.java
Original file line number Diff line number Diff line change
@@ -708,17 +708,6 @@ public static IRubyObject isDefinedSuper(ThreadContext context, IRubyObject rece
return flag ? context.runtime.getDefinedMessage(DefinedMessage.SUPER) : context.nil;
}

protected static void checkSuperDisabledOrOutOfMethod(ThreadContext context, RubyModule frameClass, String methodName) {
// FIXME: super/zsuper in top-level script still seems to have a frameClass so it will not make it into this if
if (frameClass == null) {
if (methodName == null || !methodName.equals("")) {
throw context.runtime.newNameError("superclass method '" + methodName + "' disabled", methodName);
} else {
throw context.runtime.newNoMethodError("super called outside of method", null, context.nil);
}
}
}

public static IRubyObject nthMatch(ThreadContext context, int matchNumber) {
return RubyRegexp.nth_match(matchNumber, context.getBackRef());
}
@@ -984,7 +973,7 @@ public static IRubyObject unresolvedSuper(ThreadContext context, IRubyObject sel
RubyModule klazz = context.getFrameKlazz();
String methodName = context.getCurrentFrame().getName();

checkSuperDisabledOrOutOfMethod(context, klazz, methodName);
Helpers.checkSuperDisabledOrOutOfMethod(context, klazz, methodName);
RubyModule implMod = Helpers.findImplementerIfNecessary(self.getMetaClass(), klazz);
RubyClass superClass = implMod.getSuperClass();
DynamicMethod method = superClass != null ? superClass.searchMethod(methodName) : UndefinedMethod.INSTANCE;
11 changes: 1 addition & 10 deletions core/src/main/java/org/jruby/runtime/callsite/SuperCallSite.java
Original file line number Diff line number Diff line change
@@ -398,18 +398,9 @@ protected boolean methodMissing(DynamicMethod method, IRubyObject caller) {
}

protected static RubyClass pollAndGetClass(ThreadContext context, IRubyObject self, RubyModule frameClass, String frameName) {
checkSuperDisabledOrOutOfMethod(context, frameClass, frameName);
Helpers.checkSuperDisabledOrOutOfMethod(context, frameClass, frameName);

return Helpers.findImplementerIfNecessary(self.getMetaClass(), frameClass).getSuperClass();
}

protected static void checkSuperDisabledOrOutOfMethod(ThreadContext context, RubyModule frameClass, String frameName) {
if (frameClass == null) {
if (frameName != null) {
throw context.runtime.newNameError("superclass method '" + frameName + "' disabled", frameName);
} else {
throw context.runtime.newNoMethodError("super called outside of method", null, context.runtime.getNil());
}
}
}
}