Comment #0 by david.eckardt — 2012-03-31T05:19:31Z
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.
Comment #1 by clugdbug — 2012-04-02T09:08:13Z
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!
Comment #2 by kekeniro2 — 2012-07-20T17:30:10Z
To make matters worse, the error message misses its location information.
Raised the severity from 'minor'.
Comment #3 by yebblies — 2012-07-26T05:18:24Z
I caused this by disallowing catch() in @safe code. Much like issue 6278.
Comment #4 by bugzilla — 2012-07-29T14:56:44Z
Is this really a regression? When did it work?
Comment #5 by yebblies — 2012-07-29T19:34:27Z
(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.
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".
Comment #9 by k.hara.pg — 2012-12-19T17:32:32Z
(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...