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

Commits on Apr 16, 2018

  1. Another case of String vs RubySymbol from AST. Also allowed removing …

    …one more
    
    ByteList path from IR Operands.
    enebo committed Apr 16, 2018
    Copy the full SHA
    88f6ceb View commit details
  2. More toString to idString changes.

    More error messages using str().
    enebo committed Apr 16, 2018
    Copy the full SHA
    63fede2 View commit details
12 changes: 2 additions & 10 deletions core/src/main/java/org/jruby/ast/VAliasNode.java
Original file line number Diff line number Diff line change
@@ -68,23 +68,15 @@ public <T> T accept(NodeVisitor<T> iVisitor) {
* Gets the newName.
* @return Returns a String
*/
public String getNewName() {
return newName.asJavaString();
}

public RubySymbol getNewSymbolName() {
public RubySymbol getNewName() {
return newName;
}

/**
* Gets the oldName.
* @return Returns a String
*/
public String getOldName() {
return oldName.asJavaString();
}

public RubySymbol getOldSymbolName() {
public RubySymbol getOldName() {
return oldName;
}

2 changes: 1 addition & 1 deletion core/src/main/java/org/jruby/ir/IRBuilder.java
Original file line number Diff line number Diff line change
@@ -3048,7 +3048,7 @@ public Operand buildIter(final IterNode iterNode) {
}

public Operand buildLiteral(LiteralNode literalNode) {
return new StringLiteral(literalNode.getSymbolName().getBytes());
return new StringLiteral(literalNode.getSymbolName());
}

public Operand buildLocalAsgn(LocalAsgnNode localAsgnNode) {
4 changes: 0 additions & 4 deletions core/src/main/java/org/jruby/ir/operands/FrozenString.java
Original file line number Diff line number Diff line change
@@ -48,10 +48,6 @@ public FrozenString(RubySymbol symbol) {
this(symbol.idString(), symbol.getBytes());
}

public FrozenString(ByteList bytelist) {
this(internedStringFromByteList(bytelist), bytelist);
}

/**
* IRBuild.buildGetDefinition returns a frozen string and this is for all intern'd Java strings.
*/
5 changes: 3 additions & 2 deletions core/src/main/java/org/jruby/ir/operands/StringLiteral.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package org.jruby.ir.operands;

import org.jruby.RubyString;
import org.jruby.RubySymbol;
import org.jruby.ir.IRVisitor;
import org.jruby.ir.persistence.IRReaderDecoder;
import org.jruby.ir.persistence.IRWriterEncoder;
@@ -42,8 +43,8 @@ public StringLiteral(String s) {
this.frozenString = new FrozenString(s);
}

public StringLiteral(ByteList bytes) {
this.frozenString = new FrozenString(bytes);
public StringLiteral(RubySymbol symbol) {
frozenString = new FrozenString(symbol);
}

private StringLiteral(FrozenString frozenString) {
Original file line number Diff line number Diff line change
@@ -434,7 +434,7 @@ public int unmarshalInt() throws IOException {
private IRubyObject defaultObjectUnmarshal() throws IOException {
RubySymbol className = (RubySymbol) unmarshalObject(false);

RubyClass type = getClassFromPath(runtime, className.toString());
RubyClass type = getClassFromPath(runtime, className.idString());

IRubyObject result = (IRubyObject)type.unmarshal(this);

17 changes: 17 additions & 0 deletions core/src/main/java/org/jruby/util/RubyStringBuilder.java
Original file line number Diff line number Diff line change
@@ -230,4 +230,21 @@ public static String str(Ruby runtime, String messageBegin, IRubyObject value, S

return buf.toString();
}


public static String str(Ruby runtime, String messageBegin, IRubyObject value, String messageMiddle, RubyString value2,
String messageMiddle2, IRubyObject value3, String messageMiddle3, RubyString value4, String messageEnd) {
RubyString buf = runtime.newString(messageBegin);

buf.cat19(value.asString());
buf.cat19(runtime.newString(messageMiddle));
buf.cat19(value2.asString());
buf.cat19(runtime.newString(messageMiddle2));
buf.cat19(value3.asString());
buf.cat19(runtime.newString(messageMiddle3));
buf.cat19(value4.asString());
buf.cat19(runtime.newString(messageEnd));

return buf.toString();
}
}
24 changes: 18 additions & 6 deletions core/src/main/java/org/jruby/util/TypeConverter.java
Original file line number Diff line number Diff line change
@@ -50,6 +50,7 @@
import org.jruby.runtime.builtin.IRubyObject;

import static org.jruby.util.RubyStringBuilder.str;
import static org.jruby.util.RubyStringBuilder.types;

public class TypeConverter {

@@ -257,8 +258,9 @@ public static RaiseException newTypeError(IRubyObject obj, RubyClass target, Str
}

public static RaiseException newTypeError(Ruby runtime, IRubyObject obj, RubyClass target, String methodName, IRubyObject val) {
String className = obj.getMetaClass().toString();
return runtime.newTypeError("can't convert " + className + " to " + target.getName() + " (" + className + '#' + methodName + " gives " + val.getMetaClass().getName() + ')');
IRubyObject className = types(runtime, obj.getMetaClass());
return runtime.newTypeError(str(runtime, "can't convert ", className, " to ", types(runtime, target), " (",
className, '#' + methodName + " gives ", types(runtime, val.getMetaClass()), ")"));
}

// rb_check_to_integer
@@ -383,7 +385,8 @@ public static void checkType(ThreadContext context, IRubyObject x, final RubyMod

// MISSING: special error for T_DATA of a certain type
if (xt != type.getClassIndex()) {
throw context.runtime.newTypeError("wrong argument type " + x.getMetaClass() + " (expected " + type.getName() + ')');
Ruby runtime = context.runtime;
throw context.runtime.newTypeError(str(runtime, "wrong argument type ", types(runtime, x.getMetaClass()), " (expected ", types(runtime, type), ")"));
}
}

@@ -457,7 +460,10 @@ public static IRubyObject convertToType(IRubyObject obj, RubyClass target, int c
public static IRubyObject convertToType(IRubyObject obj, RubyClass target, int convertMethodIndex, String convertMethod) {
if (target.isInstance(obj)) return obj;
IRubyObject val = convertToType(obj, target, convertMethod, true);
if (!target.isInstance(val)) throw obj.getRuntime().newTypeError(obj.getMetaClass() + "#" + convertMethod + " should return " + target.getName());
if (!target.isInstance(val)) {
Ruby runtime = obj.getRuntime();
throw runtime.newTypeError(str(runtime, types(runtime, obj.getMetaClass()), "#" + convertMethod + " should return ", types(runtime, target)));
}
return val;
}

@@ -466,7 +472,10 @@ public static IRubyObject convertToTypeWithCheck(IRubyObject obj, RubyClass targ
if (target.isInstance(obj)) return obj;
IRubyObject val = TypeConverter.convertToType(obj, target, convertMethod, false);
if (val.isNil()) return val;
if (!target.isInstance(val)) throw obj.getRuntime().newTypeError(obj.getMetaClass() + "#" + convertMethod + " should return " + target.getName());
if (!target.isInstance(val)) {
Ruby runtime = obj.getRuntime();
throw runtime.newTypeError(str(runtime, types(runtime, obj.getMetaClass()), "#" + convertMethod + " should return ", types(runtime, target)));
}
return val;
}

@@ -495,7 +504,10 @@ public static IRubyObject convertToTypeOrRaise(IRubyObject obj, RubyClass target
if (target.isInstance(obj)) return obj;
IRubyObject val = TypeConverter.convertToType(obj, target, convertMethod, true);
if (val.isNil()) return val;
if (!target.isInstance(val)) throw obj.getRuntime().newTypeError(obj.getMetaClass() + "#" + convertMethod + " should return " + target.getName());
if (!target.isInstance(val)) {
Ruby runtime = obj.getRuntime();
throw runtime.newTypeError(str(runtime, types(runtime, obj.getMetaClass()), "#" + convertMethod + " should return ", types(runtime, target)));
}
return val;
}
}