www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 21415] New: catch immutable exceptions breaks immutable

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

          Issue ID: 21415
           Summary: catch immutable exceptions breaks immutable
           Product: D
           Version: D2
          Hardware: All
                OS: All
            Status: NEW
          Severity: normal
          Priority: P1
         Component: dmd
          Assignee: nobody puremagic.com
          Reporter: destructionator gmail.com

---
immutable foo = new Exception("omg");

void main() {
        import std.stdio;
        try {
                //throw foo;
                throw new Exception("wtf");
        } catch(immutable Exception e) {
                //e.msg = "broken";
                writeln("caught ", e);
        }
}
---

In that example, it silently casts the mutable Exception to immutable.

If you throw foo and catch Exception, it silently casts the immutable Exception
to mutable. So the mutability stuff is lost here.

(I was exploring throwing immutable static exceptions as a possibility for
nogc)

--
Nov 22 2020