Skip to content

Commit

Permalink
message parameter in assert is Text
Browse files Browse the repository at this point in the history
  • Loading branch information
Akirathan committed Sep 27, 2023
1 parent be4cbf7 commit 1212276
Showing 1 changed file with 4 additions and 13 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package org.enso.interpreter.node.expression.builtin.runtime;

import com.oracle.truffle.api.Assumption;
import com.oracle.truffle.api.CompilerDirectives;
import com.oracle.truffle.api.dsl.Cached;
import com.oracle.truffle.api.dsl.Specialization;
Expand Down Expand Up @@ -30,14 +29,14 @@ public static AssertNode build() {
}

public abstract Object execute(
VirtualFrame frame, State state, @Suspend Object action, Object msg);
VirtualFrame frame, State state, @Suspend Object action, Text msg);

protected boolean isAssertionsEnabled() {
return EnsoContext.get(this).isAssertionsEnabled();
}

@Specialization(guards = "!isAssertionsEnabled()")
Object doAssertionsDisabled(VirtualFrame frame, State state, Object action, Object msg) {
Object doAssertionsDisabled(VirtualFrame frame, State state, Object action, Text msg) {
return EnsoContext.get(this).getNothing();
}

Expand All @@ -46,7 +45,7 @@ Object doAssertionsEnabled(
VirtualFrame frame,
State state,
Object action,
Object msg,
Text msg,
@Cached("create()") ThunkExecutorNode thunkExecutorNode,
@CachedLibrary(limit = "3") InteropLibrary interop,
@Cached GetStackTraceNode getStackTraceNode) {
Expand All @@ -58,22 +57,14 @@ Object doAssertionsEnabled(
.error()
.makeTypeError(builtins.function(), TypeOfNode.getUncached().execute(action), "action");
}
String message;
try {
message = interop.asString(msg);
} catch (UnsupportedMessageException e) {
return builtins
.error()
.makeTypeError(builtins.text(), TypeOfNode.getUncached().execute(msg), "message");
}
Object actionRes =
thunkExecutorNode.executeThunk(frame, action, state, BaseNode.TailStatus.TAIL_DIRECT);
try {
if (interop.asBoolean(actionRes)) {
return ctx.getNothing();
} else {
var stackTrace = getStackTraceNode.execute(frame);
return builtins.error().makeAssertionError(Text.create(message), stackTrace);
return builtins.error().makeAssertionError(msg, stackTrace);
}
} catch (UnsupportedMessageException e) {
return builtins
Expand Down

0 comments on commit 1212276

Please sign in to comment.