Skip to content

Commit

Permalink
Fix Array.Sort.
Browse files Browse the repository at this point in the history
Add assert to check BigInteger doesn't fit in Long.
  • Loading branch information
jdunkerley committed Nov 16, 2022
1 parent 77aae57 commit bfb914e
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 3 deletions.
5 changes: 3 additions & 2 deletions distribution/lib/Standard/Base/0.0.0-dev/src/Data/Vector.enso
Original file line number Diff line number Diff line change
Expand Up @@ -1107,8 +1107,9 @@ handle_incomparable_value ~function =
handle t = Panic.catch t handler=(_-> Error.throw Incomparable_Values_Error)
handle ClassCastException <|
handle No_Such_Method_Error_Data <|
handle Unsupported_Argument_Types_Data <|
function.catch Type_Error_Data handler=(_-> Error.throw Incomparable_Values_Error)
handle Type_Error_Data <|
handle Unsupported_Argument_Types_Data <|
function.catch Type_Error_Data handler=(_-> Error.throw Incomparable_Values_Error)

## PRIVATE
Creates a new vector where for each range, a corresponding section of the
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import org.enso.interpreter.node.expression.builtin.ordering.Ordering;
import org.enso.interpreter.runtime.Context;
import org.enso.interpreter.runtime.callable.argument.CallArgumentInfo;
import org.enso.interpreter.runtime.error.DataflowError;
import org.enso.interpreter.runtime.error.PanicException;
import org.enso.interpreter.runtime.state.State;

Expand Down Expand Up @@ -44,6 +45,10 @@ public int execute(VirtualFrame frame, Object comparator, State state, Object l,
return 1;
} else {
CompilerDirectives.transferToInterpreter();
if (atom instanceof DataflowError error) {
throw new PanicException(error.getPayload(), error.getLocation());
}

var ordering = getOrdering().getType();
throw new PanicException(
Context.get(this).getBuiltins().error().makeTypeError(ordering, atom, "comparator"),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import org.enso.interpreter.runtime.callable.atom.Atom;
import org.enso.interpreter.runtime.callable.function.Function;
import org.enso.interpreter.runtime.data.Array;
import org.enso.interpreter.runtime.error.DataflowError;
import org.enso.interpreter.runtime.error.PanicException;
import org.enso.interpreter.runtime.state.State;

Expand Down Expand Up @@ -97,6 +98,10 @@ private int convertResult(Object res) {
return 1;
} else {
resultProfile.enter();
if (res instanceof DataflowError error) {
throw new PanicException(error.getPayload(), error.getLocation());
}

var ordering = context.getBuiltins().ordering().getType();
throw new PanicException(
context.getBuiltins().error().makeTypeError(ordering, res, "result"), outerThis);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
import com.oracle.truffle.api.library.CachedLibrary;
import com.oracle.truffle.api.library.ExportLibrary;
import com.oracle.truffle.api.library.ExportMessage;
import org.enso.interpreter.node.expression.builtin.number.utils.BigIntegerOps;
import org.enso.interpreter.runtime.Context;
import org.enso.interpreter.runtime.data.Type;
import org.enso.interpreter.runtime.library.dispatch.TypesLibrary;
Expand All @@ -26,6 +25,7 @@ public final class EnsoBigInteger implements TruffleObject {
* @param value the value to wrap.
*/
public EnsoBigInteger(BigInteger value) {
assert(value.bitLength() > 63);
this.value = value;
}

Expand Down

0 comments on commit bfb914e

Please sign in to comment.