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

Commits on Feb 6, 2018

  1. incidentally found error in ripper while looking for something else...

    $_foo would not ever parse....
    enebo committed Feb 6, 2018
    Copy the full SHA
    d1df87a View commit details

Commits on Feb 7, 2018

  1. Yeah these symbol IDs are identifiers and so should be hard similar t…

    …o how MRI
    
    works.  We do not want them going away since we may no longer have a reference
    in the AST nor IR (actually IR does not store symbols at all but even if it did
    I would like persistence to play a future role so we can save long uncalled or
    already JITd IR to save memory).
    enebo committed Feb 7, 2018
    Copy the full SHA
    1367812 View commit details

Commits on Feb 13, 2018

  1. Still a lot of missing changes for errors but more filled in.

    const_defined? totally changed and only broken now due to missing proper logic
    for printing out type names in error messages.  Outstanding is if the string
    contains something the encoding thinks is unprintable it will display the type
    in quotes and escape the unprintable character.  dumpString is nearly correct
    but it will not correctly pick up \u0000 for \0 but instead print out \x00.
    
    Landing for now since this is again a bigish delta and it advances things a bit
    more.
    enebo committed Feb 13, 2018
    Copy the full SHA
    790425c View commit details
30 changes: 16 additions & 14 deletions core/src/main/java/org/jruby/Ruby.java
Original file line number Diff line number Diff line change
@@ -206,6 +206,7 @@
import static java.lang.invoke.MethodHandles.insertArguments;
import static java.lang.invoke.MethodType.methodType;
import static org.jruby.internal.runtime.GlobalVariable.Scope.GLOBAL;
import static org.jruby.util.RubyStringBuilder.buildString;

/**
* The Ruby object represents the top-level of a JRuby "instance" in a given VM.
@@ -1041,10 +1042,10 @@ public RubyClass defineClassUnder(String name, RubyClass superClass, ObjectAlloc
IRubyObject classObj = parent.getConstantAt(name);

if (classObj != null) {
if (!(classObj instanceof RubyClass)) throw newTypeError(name + " is not a class");
if (!(classObj instanceof RubyClass)) throw newTypeError(buildString(this, newSymbol(name), " is not a class"));
RubyClass klazz = (RubyClass)classObj;
if (klazz.getSuperClass().getRealClass() != superClass) {
throw newNameError(name + " is already defined", name);
throw newNameError(buildString(this, newSymbol(name), " is already defined"), name);
}
// If we define a class in Ruby, but later want to allow it to be defined in Java,
// the allocator needs to be updated
@@ -1057,8 +1058,8 @@ public RubyClass defineClassUnder(String name, RubyClass superClass, ObjectAlloc
boolean parentIsObject = parent == objectClass;

if (superClass == null) {
String className = parentIsObject ? name : parent.getName() + "::" + name;
warnings.warn(ID.NO_SUPER_CLASS, "no super class for `" + className + "', Object assumed");
IRubyObject className = parentIsObject ? newSymbol(name) : parent.rubyName().append(newString("::")).append(newSymbol(name));
warnings.warn(ID.NO_SUPER_CLASS, buildString(this, "no super class for `", className, "', Object assumed"));

superClass = objectClass;
}
@@ -1097,9 +1098,9 @@ public RubyModule defineModuleUnder(String name, RubyModule parent) {
if (moduleObj.isModule()) return (RubyModule)moduleObj;

if (parentIsObject) {
throw newTypeError(moduleObj.getMetaClass().getName() + " is not a module");
throw newTypeError(buildString(this, moduleObj.getMetaClass().rubyName(), " is not a module"));
} else {
throw newTypeError(parent.getName() + "::" + moduleObj.getMetaClass().getName() + " is not a module");
throw newTypeError(buildString(this, parent.rubyName(), "::", moduleObj.getMetaClass().rubyName(), " is not a module"));
}
}

@@ -1118,7 +1119,7 @@ public RubyModule getOrCreateModule(String name) {
if (module == null) {
module = defineModule(name);
} else if (!module.isModule()) {
throw newTypeError(name + " is not a Module");
throw newTypeError(buildString(this, newSymbol(name), " is not a Module"));
}

return (RubyModule) module;
@@ -2862,7 +2863,7 @@ public PrintStream getOutputStream() {

public RubyModule getClassFromPath(final String path) {
if (path.length() == 0 || path.charAt(0) == '#') {
throw newTypeError("can't retrieve anonymous class " + path);
throw newTypeError(buildString(this, "can't retrieve anonymous class ", newSymbol(path)));
}

RubyModule c = getObject();
@@ -2874,14 +2875,14 @@ public RubyModule getClassFromPath(final String path) {

if ( p < l && path.charAt(p) == ':' ) {
if ( ++p < l && path.charAt(p) != ':' ) {
throw newTypeError("undefined class/module " + str);
throw newTypeError(buildString(this, "undefined class/module ", newSymbol(str)));
}
pbeg = ++p;
}

IRubyObject cc = c.getConstant(str);
if ( ! ( cc instanceof RubyModule ) ) {
throw newTypeError(path + " does not refer to class/module");
throw newTypeError(buildString(this, newSymbol(path), " does not refer to class/module"));
}
c = (RubyModule) cc;
}
@@ -3580,7 +3581,7 @@ public RaiseException newArgumentError(int got, int expected) {
}

public RaiseException newArgumentError(String name, int got, int expected) {
return newRaiseException(getArgumentError(), "wrong number of arguments calling `" + name + "` (" + got + " for " + expected + ")");
return newRaiseException(getArgumentError(), buildString(this, "wrong number of arguments calling `", newSymbol(name), ("` (" + got + " for " + expected + ")")));
}

public RaiseException newErrnoEBADFError() {
@@ -4084,7 +4085,7 @@ public RaiseException newFrozenError(String objectType) {

public RaiseException newFrozenError(String objectType, boolean runtimeError) {
// TODO: Should frozen error have its own distinct class? If not should more share?
return newRaiseException(getRuntimeError(), "can't modify frozen " + objectType);
return newRaiseException(getRuntimeError(), buildString(this, "can't modify frozen ", newSymbol(objectType)));
}

public RaiseException newSystemStackError(String message) {
@@ -4132,8 +4133,9 @@ public RaiseException newTypeError(IRubyObject receivedObject, RubyModule expect
}

public RaiseException newTypeError(IRubyObject receivedObject, String expectedType) {
return newRaiseException(getTypeError(), "wrong argument type " +
receivedObject.getMetaClass().getRealClass() + " (expected " + expectedType + ")");
return newRaiseException(getTypeError(),
buildString(this, "wrong argument type ", receivedObject.getMetaClass().getRealClass().rubyName(),
" (expected ", newSymbol(expectedType), ")"));
}

public RaiseException newEOFError() {
19 changes: 11 additions & 8 deletions core/src/main/java/org/jruby/RubyBasicObject.java
Original file line number Diff line number Diff line change
@@ -81,6 +81,7 @@
import static org.jruby.runtime.invokedynamic.MethodNames.OP_CMP;
import static org.jruby.runtime.invokedynamic.MethodNames.EQL;
import static org.jruby.runtime.invokedynamic.MethodNames.INSPECT;
import static org.jruby.util.RubyStringBuilder.buildString;
import static org.jruby.util.io.EncodingUtils.encStrBufCat;

import org.jruby.runtime.ivars.VariableTableManager;
@@ -617,7 +618,7 @@ public final boolean respondsTo(String name) {
return respondTo.call(context, this, metaClass, respondName, mname).isTrue();
}
if ( arity.required() != 2 ) {
throw runtime.newArgumentError(respondName + " must accept 1 or 2 arguments (requires " + arity.getValue() + ")");
throw runtime.newArgumentError(buildString(runtime, runtime.newSymbol(respondName), " must accept 1 or 2 arguments (requires " + arity.getValue() + ")"));
}
}

@@ -681,7 +682,7 @@ public Class getJavaClass() {
public String asJavaString() {
IRubyObject str = checkStringType();
if (!str.isNil()) return ((RubyString) str).asJavaString();
throw getRuntime().newTypeError(inspect() + " is not a string");
throw getRuntime().newTypeError(buildString(getRuntime(), inspect(), " is not a string"));
}

/** rb_obj_as_string
@@ -752,7 +753,7 @@ public RubyInteger convertToInteger() {
IRubyObject result = TypeConverter.convertToType(context, this, runtime.getInteger(), sites.to_int_checked, true);

if (!(result instanceof RubyInteger)) {
throw getRuntime().newTypeError(getMetaClass().getName() + "#to_int should return Integer");
throw getRuntime().newTypeError(buildString(runtime, getMetaClass().rubyName(), "#to_int should return Integer"));
}

return (RubyInteger) result;
@@ -778,7 +779,8 @@ public RubyInteger convertToInteger(String convertMethod) {
}

if (!(result instanceof RubyInteger)) {
throw getRuntime().newTypeError(getMetaClass().getName() + '#' + convertMethod + " should return Integer");
Ruby runtime = getRuntime();
throw runtime.newTypeError(buildString(runtime, getMetaClass().rubyName(), "#", runtime.newSymbol(convertMethod), " should return Integer"));
}

return (RubyInteger) result;
@@ -985,7 +987,7 @@ public IRubyObject rbClone(ThreadContext context, IRubyObject maybeOpts) {
if (!opts.isNil()) {
IRubyObject freeze = ((RubyHash) opts).fastARef(runtime.newSymbol("freeze"));
if (freeze != null && freeze != runtime.getTrue() && freeze != runtime.getFalse()) {
throw runtime.newArgumentError("unexpected value for freeze: " + freeze.getType().getName());
throw runtime.newArgumentError(buildString(runtime, "unexpected value for freeze: ", freeze.getType().rubyName()));
}
if (freeze != null) {
kwfreeze = freeze.isTrue();
@@ -1000,7 +1002,7 @@ private IRubyObject rbCloneInternal(ThreadContext context, boolean freeze) {

if (isSpecialObject()) {
if (!freeze) {
throw runtime.newArgumentError("can't unfreeze " + getType().getName());
throw runtime.newArgumentError(buildString(runtime, "can't unfreeze ", getType().rubyName()));
}
return this;
}
@@ -2529,7 +2531,8 @@ public RubyArray singleton_methods(ThreadContext context, IRubyObject[] args) {
}

public IRubyObject singleton_method(IRubyObject name) {
final String methodName = TypeConverter.checkID(name).asJavaString();
RubySymbol symbol = TypeConverter.checkID(name);
final String methodName = symbol.asJavaString();
final RubyClass klass = metaClass;
if (klass.isSingleton()) {
DynamicMethod method = klass.searchMethod(methodName);
@@ -2539,7 +2542,7 @@ public IRubyObject singleton_method(IRubyObject name) {
return newMethod;
}
}
throw getRuntime().newNameError("undefined method `" + methodName + "' for `" + inspect() + '\'', methodName);
throw getRuntime().newNameError(buildString(getRuntime(), "undefined method `", symbol, "' for `", inspect(), "'"), methodName);
}

/** rb_obj_method
6 changes: 4 additions & 2 deletions core/src/main/java/org/jruby/RubyIO.java
Original file line number Diff line number Diff line change
@@ -49,6 +49,8 @@
import org.jruby.util.StringSupport;
import org.jruby.util.io.ChannelFD;
import org.jruby.util.io.EncodingUtils;

import static org.jruby.util.RubyStringBuilder.buildString;
import static org.jruby.util.io.EncodingUtils.vmodeVperm;
import static org.jruby.util.io.EncodingUtils.vperm;

@@ -883,10 +885,10 @@ public static IRubyObject newInstance(ThreadContext context, IRubyObject recv, I
RubyClass klass = (RubyClass)recv;

if (block.isGiven()) {
String className = klass.getName();
IRubyObject className = klass.rubyName();
context.runtime.getWarnings().warn(
ID.BLOCK_NOT_ACCEPTED,
className + "::new() does not take block; use " + className + "::open() instead");
buildString(context.runtime, className, "::new() does not take block; use ", className, "::open() instead"));
}

return klass.newInstance(context, args, block);
86 changes: 49 additions & 37 deletions core/src/main/java/org/jruby/RubyModule.java
Original file line number Diff line number Diff line change
@@ -108,7 +108,9 @@
import org.jruby.runtime.opto.OptoFactory;
import org.jruby.runtime.profile.MethodEnhancer;
import org.jruby.util.ByteList;
import org.jruby.util.ByteListHelper;
import org.jruby.util.ClassProvider;
import org.jruby.util.CommonByteLists;
import org.jruby.util.IdUtil;
import org.jruby.util.StringSupport;
import org.jruby.util.TypeConverter;
@@ -1864,7 +1866,7 @@ public RubyModule defineOrGetModuleUnder(String name) {
IRubyObject moduleObj = getConstantAtSpecial(name);
RubyModule module;
if (moduleObj != null) {
if (!moduleObj.isModule()) throw runtime.newTypeError(name + " is not a module");
if (!moduleObj.isModule()) throw runtime.newTypeError(buildString(runtime, runtime.newSymbol(name), " is not a module"));
module = (RubyModule)moduleObj;
} else if ((module = searchProvidersForModule(name)) != null) {
// reopen a java module
@@ -3343,49 +3345,45 @@ public RubyBoolean const_defined_p(ThreadContext context, IRubyObject symbol) {
return const_defined_p19(context, new IRubyObject[]{symbol});
}

private RubyBoolean constantDefined(Ruby runtime, RubySymbol symbol, boolean inherit) {
if (symbol.validConstantName()) {
return runtime.newBoolean(getConstantSkipAutoload(symbol.getRawString(), inherit, inherit) != null);
}

// FIXME: bytelist_love: nameError should use symbol and not Java String.
throw runtime.newNameError(buildString(runtime, "wrong constant name", symbol), symbol.asJavaString());
}

@JRubyMethod(name = "const_defined?", required = 1, optional = 1)
public RubyBoolean const_defined_p19(ThreadContext context, IRubyObject[] args) {
final Ruby runtime = context.runtime;
boolean inherit = args.length == 1 || ( ! args[1].isNil() && args[1].isTrue() );
Ruby runtime = context.runtime;
boolean inherit = args.length == 1 || (!args[1].isNil() && args[1].isTrue());

final IRubyObject symbol = args[0];
final String fullName = symbol.asJavaString();
String name = fullName;
if (args[0] instanceof RubySymbol) return constantDefined(runtime, ((RubySymbol) args[0]), inherit);

int sep = name.indexOf("::");
// symbol form does not allow ::
if (symbol instanceof RubySymbol && sep != -1) throw runtime.newNameError("wrong constant name", name);
RubyString fullName = args[0].convertToString();

RubyModule mod = this;
IRubyObject value = ByteListHelper.split(fullName.getByteList(), CommonByteLists.COLON_COLON, (index, segment, module) -> {
if (index == 0) {
if (segment.realSize() == 0) return runtime.getObject(); // '::Foo...'
module = this;
}

if (sep == 0) { // ::Foo::Bar
mod = runtime.getObject();
name = name.substring(2);
}
String id = RubySymbol.newConstantSymbol(runtime, fullName, segment).getRawString();
IRubyObject obj = ((RubyModule) module).getConstantNoConstMissing(id, inherit, inherit);

// Bare ::
if (name.length() == 0) {
throw runtime.newNameError("wrong constant name ", fullName);
}
if (obj == null) return null;
if (!(obj instanceof RubyModule)) throw runtime.newTypeError(segment + " does not refer to class/module");

IRubyObject obj;
while ( ( sep = name.indexOf("::") ) != -1 ) {
final String segment = name.substring(0, sep);
if (segment.length() == 0) {
throw runtime.newNameError("wrong constant name " + fullName, name);
}
obj = mod.getConstantNoConstMissing(validateConstant(segment, symbol), inherit, inherit);
if (obj == null) return runtime.getFalse();
if (obj instanceof RubyModule) {
mod = (RubyModule) obj;
} else {
throw runtime.newTypeError(segment + " does not refer to class/module");
}
name = name.substring(sep + 2);
}
return obj;
}, (index, segment, module) -> {
if (module == null) module = this; // Bare 'Foo'

String id = RubySymbol.newConstantSymbol(runtime, fullName, segment).getRawString();
return ((RubyModule) module).getConstantSkipAutoload(id, inherit, inherit);
});

obj = mod.getConstantSkipAutoload(validateConstant(name, symbol), inherit, inherit);
return runtime.newBoolean(obj != null);
return runtime.newBoolean(value != null);
}

/** rb_mod_const_get
@@ -3444,8 +3442,22 @@ public IRubyObject const_get_2_0(ThreadContext context, IRubyObject[] args) {
*
*/
@JRubyMethod(name = "const_set", required = 2)
public IRubyObject const_set(IRubyObject symbol, IRubyObject value) {
return setConstant(validateConstant(symbol).intern(), value);
public IRubyObject const_set(IRubyObject name, IRubyObject value) {
RubySymbol symbol;

if (name instanceof RubySymbol) {
symbol = (RubySymbol) name;
} else {
symbol = RubySymbol.newHardSymbol(getRuntime(), name.convertToString().getByteList());
}

if (!symbol.validConstantName()) {
// FIXME: bytelist_love: nameError should use symbol and not Java String.
throw getRuntime().newNameError(buildString(getRuntime(), "wrong constant name ", name), symbol.asJavaString());

}

return setConstant(symbol.getRawString(), value);
}

@JRubyMethod(name = "remove_const", required = 1, visibility = PRIVATE)
Loading