[Issue 21443] New: scope (failure) with a return breaks safety

d-bugmail at puremagic.com d-bugmail at puremagic.com
Wed Dec 2 11:15:37 UTC 2020


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

          Issue ID: 21443
           Summary: scope (failure) with a return breaks safety
           Product: D
           Version: D2
          Hardware: All
                OS: All
            Status: NEW
          Severity: major
          Priority: P1
         Component: dmd
          Assignee: nobody at puremagic.com
          Reporter: andrej.mitrovich at gmail.com

-----
ulong get () @safe nothrow
{
    scope (failure) return 10;
    throw new Error("");
}

void main () @safe
{
    assert(get() == 10);  // passes
}
-----

It should not be allowed to do a `return` inside of a `scope (failure)`,
because currently scope failure also handles Errors. In this case any Error
thrown is not re-thrown, and the function simply returns a value.

That's a big hole in safety IMO.

--


More information about the Digitalmars-d-bugs mailing list