Thread overview
[Issue 7049] New: Multiple scope(failure) blocks don't work in @safe code
Dec 02, 2011
klickverbot
Dec 02, 2011
Jonathan M Davis
Aug 20, 2013
Andrej Mitrovic
December 02, 2011
http://d.puremagic.com/issues/show_bug.cgi?id=7049

           Summary: Multiple scope(failure) blocks don't work in @safe
                    code
           Product: D
           Version: D2
          Platform: Other
        OS/Version: All
            Status: NEW
          Keywords: rejects-valid
          Severity: normal
          Priority: P2
         Component: DMD
        AssignedTo: nobody@puremagic.com
        ReportedBy: code@klickverbot.at


--- Comment #0 from klickverbot <code@klickverbot.at> 2011-12-02 08:49:46 PST ---
---
@safe void foo() {
  scope (failure) {}
  scope (failure) {}
}
---

DMD 2.057 Git (887dda0ba) gives:
---
Error: can only catch class objects derived from Exception in @safe code, not
'object.Throwable'
Error: undefined identifier __o1300
---

The reason for this are the artificial try/catch blocks generated around statement.c:530.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
December 02, 2011
http://d.puremagic.com/issues/show_bug.cgi?id=7049


Jonathan M Davis <jmdavisProg@gmx.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |jmdavisProg@gmx.com


--- Comment #1 from Jonathan M Davis <jmdavisProg@gmx.com> 2011-12-02 08:54:17 PST ---
That's odd. That would imply that the try-catch blocks generated by
scope(failure) are using catch(Throwable) instead of catch(Exception), but
scope statements are supposed to be skipped when Errors are thrown, so there's
no reason for them be catching Throwable instead of Exception.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
August 20, 2013
http://d.puremagic.com/issues/show_bug.cgi?id=7049


hsteoh@quickfur.ath.cx changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
                 CC|                            |hsteoh@quickfur.ath.cx
         Resolution|                            |WORKSFORME


--- Comment #2 from hsteoh@quickfur.ath.cx 2013-08-19 20:15:35 PDT ---
Seems to be fixed in git HEAD. To prove that it actually works, I expanded the test code a bit:

----------
import std.stdio;
int count = 0;
@safe void foo() {
  scope (failure) { count++; }
  scope (failure) { count++; }
  throw new Exception("failed");
}
void main() {
    try {
        foo();
    } catch(Exception e) {
    }
    writeln(count);
}
----------

Output:
2

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
August 20, 2013
http://d.puremagic.com/issues/show_bug.cgi?id=7049


Andrej Mitrovic <andrej.mitrovich@gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |andrej.mitrovich@gmail.com


--- Comment #3 from Andrej Mitrovic <andrej.mitrovich@gmail.com> 2013-08-19 20:20:06 PDT ---
It would be great to add these test-cases of worksforme bugs to the test-suite, if they're not already there.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
August 20, 2013
http://d.puremagic.com/issues/show_bug.cgi?id=7049



--- Comment #4 from hsteoh@quickfur.ath.cx 2013-08-19 20:33:32 PDT ---
https://github.com/D-Programming-Language/dmd/pull/2484

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
August 21, 2013
http://d.puremagic.com/issues/show_bug.cgi?id=7049



--- Comment #5 from github-bugzilla@puremagic.com 2013-08-20 20:47:03 PDT ---
Commits pushed to master at https://github.com/D-Programming-Language/dmd

https://github.com/D-Programming-Language/dmd/commit/18af82ec425cfc2d5fc86f78648c02a9c6efcbd0 Add test case for issue 7049.

https://github.com/D-Programming-Language/dmd/commit/85c033631b6512163d7bf871da49c12a25651605 Merge pull request #2484 from quickfur/test7049

Add test case for issue 7049.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------