www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 22026] New: checkaction=context: Exception thrown by toString

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 puremagic.com
          Reporter: moonlightsentinel 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.

--
Jun 15