Thread overview
[Issue 7803] New: scope(success) in nothrow/@safe functions causes compile errors
Mar 31, 2012
David Eckardt
Apr 02, 2012
Don
[Issue 7803] Regression(2.054) scope(success) in nothrow/@safe functions causes compile errors
Jul 26, 2012
yebblies
Jul 29, 2012
Walter Bright
Jul 30, 2012
yebblies
Dec 19, 2012
Kenji Hara
Dec 20, 2012
Kenji Hara
Dec 20, 2012
Kenji Hara
March 31, 2012
http://d.puremagic.com/issues/show_bug.cgi?id=7803

           Summary: scope(success) in nothrow/@safe functions causes
                    compile errors
           Product: D
           Version: D2
          Platform: All
        OS/Version: All
            Status: NEW
          Severity: minor
          Priority: P2
         Component: DMD
        AssignedTo: nobody@puremagic.com
        ReportedBy: david.eckardt@sociomantic.com


--- Comment #0 from David Eckardt <david.eckardt@sociomantic.com> 2012-03-31 05:19:31 PDT ---
Example code:

---
module test;

@safe int f() {
    scope(success) {/* ... */}
    return 3;
}

nothrow int g() {
    scope(success) {/* ... */}
    return 3;
}
---

DMD reports these compile-time errors:

Error: can only catch class objects derived from Exception in @safe code, not 'object.Throwable'

Error: object.Throwable is thrown but not caught test.d(8): Error: function test.g 'g' is nothrow yet may throw

When using scope(exit) instead, the example code compiles successfully.

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


Don <clugdbug@yahoo.com.au> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |clugdbug@yahoo.com.au


--- Comment #1 from Don <clugdbug@yahoo.com.au> 2012-04-02 09:08:13 PDT ---
This is happening because

scope(success) { success_clause; }
...

gets transformed into:

try {
  ...
}
catch(Throwable t)
{
   success_clause;
   throw t;
}

Obviously the compiler shouldn't generate an error for code it wrote!

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


kekeniro2@yahoo.co.jp changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |kekeniro2@yahoo.co.jp
           Severity|minor                       |normal


--- Comment #2 from kekeniro2@yahoo.co.jp 2012-07-20 17:30:10 PDT ---
To make matters worse, the error message misses its location information.

Raised the severity from 'minor'.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
July 26, 2012
http://d.puremagic.com/issues/show_bug.cgi?id=7803


yebblies <yebblies@gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |yebblies@gmail.com
            Summary|scope(success) in           |Regression(2.054)
                   |nothrow/@safe functions     |scope(success) in
                   |causes compile errors       |nothrow/@safe functions
                   |                            |causes compile errors
           Severity|normal                      |regression


--- Comment #3 from yebblies <yebblies@gmail.com> 2012-07-26 22:18:24 EST ---
I caused this by disallowing catch() in @safe code.  Much like issue 6278.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
July 29, 2012
http://d.puremagic.com/issues/show_bug.cgi?id=7803


Walter Bright <bugzilla@digitalmars.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |bugzilla@digitalmars.com


--- Comment #4 from Walter Bright <bugzilla@digitalmars.com> 2012-07-29 14:56:44 PDT ---
Is this really a regression? When did it work?

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
July 30, 2012
http://d.puremagic.com/issues/show_bug.cgi?id=7803



--- Comment #5 from yebblies <yebblies@gmail.com> 2012-07-30 12:34:27 EST ---
(In reply to comment #4)
> Is this really a regression? When did it work?

I haven't tested it, but I assume it is the same cause as issue 6278, and needs the same fix (mark generated catches so they don't get checked for @safety.

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


Kenji Hara <k.hara.pg@gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|                            |pull


--- Comment #6 from Kenji Hara <k.hara.pg@gmail.com> 2012-12-18 19:24:29 PST ---
https://github.com/D-Programming-Language/dmd/pull/1388

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



--- Comment #7 from github-bugzilla@puremagic.com 2012-12-19 06:41:36 PST ---
Commits pushed to master at https://github.com/D-Programming-Language/dmd

https://github.com/D-Programming-Language/dmd/commit/2926c0a493254efeaaff21fe920a00db58f46693
partially fix Issue 7803 - Regression(2.054) scope(success) in nothrow/@safe
functions causes compile errors

https://github.com/D-Programming-Language/dmd/commit/d6a2b1c95d8409e5e2ff0b60de64e2ee25283d96 Merge pull request #1388 from 9rnsr/fix7803

partially fix Issue 7803 - Regression(2.054) scope(success) in nothrow/@safe
functions causes compile errors

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


Kenji Hara <k.hara.pg@gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
         Resolution|                            |FIXED


--- Comment #8 from Kenji Hara <k.hara.pg@gmail.com> 2012-12-19 17:25:29 PST ---
Now original code can be compiled as expected.

Different from bug 6278, the internal catch and re-throwing which used for scope(success) do not affect to whole code semantics. So I mark this "resolved fixed".

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



--- Comment #9 from Kenji Hara <k.hara.pg@gmail.com> 2012-12-19 17:32:32 PST ---
(In reply to comment #8)
> Now original code can be compiled as expected.
> 
> Different from bug 6278, the internal catch and re-throwing which used for scope(success) do not affect to whole code semantics. So I mark this "resolved fixed".

But, there is still internal semantic inconsistency:
- Catching Throwable object in @safe code
- Re-throwing Throwable object in nothrow code

In these points, I couldn't resolve the issues cleanly...

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