Bug 7803 – Regression(2.054) scope(success) in nothrow/@safe functions causes compile errors

Status
RESOLVED
Resolution
FIXED
Severity
regression
Priority
P2
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2012-03-31T05:19:00Z
Last change time
2012-12-19T17:32:32Z
Keywords
pull, rejects-valid
Assigned to
nobody
Creator
david.eckardt

Comments

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.
Comment #6 by k.hara.pg — 2012-12-18T19:24:29Z
Comment #7 by github-bugzilla — 2012-12-19T06:41:36Z
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
Comment #8 by k.hara.pg — 2012-12-19T17:25:29Z
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...