[Issue 22026] New: checkaction=context: Exception thrown by toString hides assertion failures

d-bugmail at puremagic.com d-bugmail at puremagic.com
Tue Jun 15 21:48:43 UTC 2021


https://issues.dlang.org/show_bug.cgi?id=22026

          Issue ID: 22026
           Summary: checkaction=context: Exception thrown by toString
                    hides assertion failures
           Product: D
           Version: D2
          Hardware: All
                OS: All
            Status: NEW
          Severity: normal
          Priority: P1
         Component: druntime
          Assignee: nobody at puremagic.com
          Reporter: moonlightsentinel at disroot.org

checkaction=context calls user-defined toString-methods if defined. But those
can throw an exception which masks the real assertion failure, e.g.:

truct MayThrow
{
    int i;
    string toString()
    {
        if (i == 1)
            throw new Exception("Error");
        return "Some message";
    }
}

assert(MayThrow(0) == MayThrow(1));
====================================================

This test will report the exception from toString(), not the assertion failure.

--


More information about the Digitalmars-d-bugs mailing list