Skip to content

Commit e80ca10

Browse files
committed
Fix lifetime issue with assert messages, see #623
1 parent ba35a6d commit e80ca10

File tree

1 file changed

+10
-3
lines changed

1 file changed

+10
-3
lines changed

src/builtins.ts

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3943,9 +3943,16 @@ export function compileAbort(
39433943
var abortInstance = program.abortInstance;
39443944
if (!(abortInstance && compiler.compileFunction(abortInstance))) return module.unreachable();
39453945

3946-
var messageArg = message != null
3947-
? compiler.compileExpression(message, stringInstance.type, ContextualFlags.IMPLICIT)
3948-
: stringInstance.type.toNativeZero(module);
3946+
var messageArg: ExpressionRef;
3947+
if (message !== null) {
3948+
// The message argument works much like an arm of an IF that does not become executed if the
3949+
// assertion succeeds respectively is only being computed if the program actually crashes.
3950+
// Hence, let's make it so that the autorelease is skipped at the end of the current block,
3951+
// essentially ignoring the message GC-wise. Doesn't matter anyway on a crash.
3952+
messageArg = compiler.compileExpression(message, stringInstance.type, ContextualFlags.IMPLICIT | ContextualFlags.SKIP_AUTORELEASE);
3953+
} else {
3954+
messageArg = stringInstance.type.toNativeZero(module);
3955+
}
39493956

39503957
var filenameArg = compiler.ensureStaticString(reportNode.range.source.normalizedPath);
39513958

0 commit comments

Comments
 (0)