Introduced by https://github.com/dlang/dmd/pull/5075 Specifically, the `semantic3Errors` can be set when gagged, but remain set when later ungagged. In opover.d, a function looked up with `semantic3Errors` can cause another expression to be set to `new ErrorExp()`. This expression then causes a cascaded error in `StatementSemanticVisitor.visit(ExpStatement)` where the `return setError()` is executed. `setError()` asserts if the global error count is not set. If that assert is disabled, another one asserts in `e2ir.d` which is not expecting an `ErrorStatement`. It's hard to come up with a non-Phobos test case for this due to the massive complexity of Phobos.
@WalterBright created dlang/dmd pull request #9425 "partially address Issue 19722 - botched implementation of semantic3Er…" fixing this issue: - partially address Issue 19722 - botched implementation of semantic3Errors causes compiler assert fail https://github.com/dlang/dmd/pull/9425
Also related to https://github.com/dlang/dmd/pull/4950
dlang/dmd pull request #9425 "partially address Issue 19722 - botched implementation of semantic3Er…" was merged into master: - 63ac6902e763b439cf3c843f25c3ddf8dc13acaa by Walter Bright: partially address Issue 19722 - botched implementation of semantic3Errors causes compiler assert fail https://github.com/dlang/dmd/pull/9425