Skip to content

Commit

Permalink
[Truffle] Handle the case where 'to_str' returns something other than…
Browse files Browse the repository at this point in the history
… a RubyString.
  • Loading branch information
nirvdrum committed Dec 5, 2014
1 parent 8e54c7d commit e29effb
Showing 1 changed file with 21 additions and 3 deletions.
24 changes: 21 additions & 3 deletions core/src/main/java/org/jruby/truffle/nodes/core/KernelNodes.java
Original file line number Diff line number Diff line change
Expand Up @@ -509,10 +509,10 @@ public Object eval(RubyString source, RubyBinding binding) {
public Object eval(VirtualFrame frame, RubyBasicObject object, UndefinedPlaceholder binding) {
notDesignedForCompilation();

try {
RubyString coerced = (RubyString) toStr.call(frame, object, "to_str", null);
Object coerced;

return getContext().eval(coerced.toString(), this);
try {
coerced = toStr.call(frame, object, "to_str", null);
} catch (RaiseException e) {
if (e.getRubyException().getLogicalClass() == getContext().getCoreLibrary().getNoMethodErrorClass()) {
throw new RaiseException(
Expand All @@ -523,6 +523,24 @@ public Object eval(VirtualFrame frame, RubyBasicObject object, UndefinedPlacehol
throw e;
}
}

if (coerced instanceof RubyString) {
return getContext().eval(coerced.toString(), this);
} else {
String coercedClassName = coerced.getClass().getName();

if (coerced instanceof RubyBasicObject) {
coercedClassName = ((RubyBasicObject) coerced).getLogicalClass().getName();
}

throw new RaiseException(
getContext().getCoreLibrary().typeError(
String.format("can't convert %s to String (%s#to_str gives %s)",
object.getLogicalClass().getName(),
object.getLogicalClass().getName(),
coercedClassName),
this));
}
}
}

Expand Down

0 comments on commit e29effb

Please sign in to comment.