Skip to content
Permalink
Browse files
[Truffle] Handle the case where 'to_str' returns something other than…
… a RubyString.
  • Loading branch information
nirvdrum committed Dec 5, 2014
1 parent 8e54c7d commit e29effbd6524ecd3cdb47e903347d5789e058f85
Showing with 21 additions and 3 deletions.
  1. +21 −3 core/src/main/java/org/jruby/truffle/nodes/core/KernelNodes.java
@@ -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(
@@ -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));
}
}
}

0 comments on commit e29effb

Please sign in to comment.