Skip to content

Commit

Permalink
[Truffle] Remove erroneous cases in fixnum_coerce.
Browse files Browse the repository at this point in the history
See #2834.
  • Loading branch information
eregon committed Apr 15, 2015
1 parent 8cd45e0 commit 30934c2
Showing 1 changed file with 3 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -62,28 +62,9 @@ public RubyArray coerce(long a, int b) {
return new RubyArray(getContext().getCoreLibrary().getArrayClass(), new long[]{b, a}, 2);
}

@Specialization
public RubyArray coerce(int a, RubyString b) {
try {
return new RubyArray(getContext().getCoreLibrary().getArrayClass(), new double[]{Double.parseDouble(b.toString()), a}, 2);
} catch (NumberFormatException e) {
throw new RaiseException(getContext().getCoreLibrary().argumentError("invalid value for Float", this));
}
}

@Specialization(guards = {"!isRubyString(arguments[1])", "!isRubyNilObject(arguments[1])"})
public RubyArray coerce(VirtualFrame frame, int a, Object b) {
if (toFRespond.doesRespondTo(frame, "to_f", b)) {
final Object bFloat = toF.call(frame, b, "to_f", null);

if (bFloat instanceof Double) {
return new RubyArray(getContext().getCoreLibrary().getArrayClass(), new double[]{(double) bFloat, a}, 2);
} else {
throw new RaiseException(getContext().getCoreLibrary().typeError("?", this));
}
} else {
throw new RaiseException(getContext().getCoreLibrary().typeError("?", this));
}
@Specialization(guards = "!isInteger(arguments[1])")
public RubyArray coerce(int a, Object b) {
return null; // Primitive failure
}

}
Expand Down

0 comments on commit 30934c2

Please sign in to comment.