i was looking at some code in the compiler like:
DiagnosticTransaction txn(ctx.Diags);
ctx.Diags.diagnose(/*some error*/);
assert(!ctx.Diags.hadAnyError());
txn.abort();
assert(!ctx.Diags.hadAnyError());
and to my surprise found that this was the case:
DiagnosticTransaction txn(ctx.Diags);
ctx.Diags.diagnose(/*some error*/);
assert(!ctx.Diags.hadAnyError());
assert(txn.hasErrors());
txn.abort();
assert(!ctx.Diags.hadAnyError()); // 💥 assertion failure
this appears to be due to the hasErrors()
method calling determineBehavior on the underlying engine state, which persists the error flags regardless of transaction state.
should this behavior be considered a bug?
edit – i'm assuming this is unintentional. reported here