| 1 |
/* |
| 2 |
TEST_OUTPUT: |
| 3 |
--- |
| 4 |
fail_compilation/fail2456.d(14): Error: cannot put `scope(success)` statement inside `finally` block |
| 5 |
--- |
| 6 |
*/ |
| 7 |
void test_success() |
| 8 |
{ |
| 9 |
try |
| 10 |
{ |
| 11 |
} |
| 12 |
finally |
| 13 |
{ |
| 14 |
scope(success) {} // NG |
| 15 |
} |
| 16 |
} |
| 17 |
|
| 18 |
/* |
| 19 |
TEST_OUTPUT: |
| 20 |
--- |
| 21 |
fail_compilation/fail2456.d(31): Error: cannot put `scope(failure)` statement inside `finally` block |
| 22 |
--- |
| 23 |
*/ |
| 24 |
void test_failure() |
| 25 |
{ |
| 26 |
try |
| 27 |
{ |
| 28 |
} |
| 29 |
finally |
| 30 |
{ |
| 31 |
scope(failure) {} // NG |
| 32 |
} |
| 33 |
} |
| 34 |
|
| 35 |
/* |
| 36 |
TEST_OUTPUT: |
| 37 |
--- |
| 38 |
--- |
| 39 |
*/ |
| 40 |
void test_exit() |
| 41 |
{ |
| 42 |
try |
| 43 |
{ |
| 44 |
} |
| 45 |
finally |
| 46 |
{ |
| 47 |
scope(exit) {} // OK |
| 48 |
} |
| 49 |
} |
| 50 |
|
| 51 |
/* |
| 52 |
TEST_OUTPUT: |
| 53 |
--- |
| 54 |
fail_compilation/fail2456.d(64): Error: cannot put `scope(success)` statement inside `scope(success)` |
| 55 |
fail_compilation/fail2456.d(65): Error: cannot put `scope(failure)` statement inside `scope(success)` |
| 56 |
fail_compilation/fail2456.d(78): Error: cannot put `scope(success)` statement inside `scope(exit)` |
| 57 |
fail_compilation/fail2456.d(79): Error: cannot put `scope(failure)` statement inside `scope(exit)` |
| 58 |
--- |
| 59 |
*/ |
| 60 |
void test2456a() |
| 61 |
{ |
| 62 |
scope(success) |
| 63 |
{ |
| 64 |
scope(success) {} // NG |
| 65 |
scope(failure) {} // NG |
| 66 |
scope(exit) {} // OK |
| 67 |
} |
| 68 |
|
| 69 |
scope(failure) |
| 70 |
{ |
| 71 |
scope(success) {} // OK |
| 72 |
scope(failure) {} // OK |
| 73 |
scope(exit) {} // OK |
| 74 |
} |
| 75 |
|
| 76 |
scope(exit) |
| 77 |
{ |
| 78 |
scope(success) {} // NG |
| 79 |
scope(failure) {} // NG |
| 80 |
scope(exit) {} // OK |
| 81 |
} |
| 82 |
} |
| 83 |
|
| 84 |
/* |
| 85 |
TEST_OUTPUT: |
| 86 |
--- |
| 87 |
fail_compilation/fail2456.d(96): Error: cannot put `catch` statement inside `scope(success)` |
| 88 |
fail_compilation/fail2456.d(108): Error: cannot put `catch` statement inside `scope(exit)` |
| 89 |
--- |
| 90 |
*/ |
| 91 |
void test2456b() |
| 92 |
{ |
| 93 |
scope(success) |
| 94 |
{ |
| 95 |
try {} |
| 96 |
catch (Throwable) {} // NG |
| 97 |
} |
| 98 |
|
| 99 |
scope(failure) |
| 100 |
{ |
| 101 |
try {} |
| 102 |
catch (Throwable) {} // OK |
| 103 |
} |
| 104 |
|
| 105 |
scope(exit) |
| 106 |
{ |
| 107 |
try {} |
| 108 |
catch (Throwable) {} // NG |
| 109 |
} |
| 110 |
} |
| 111 |
|
| 112 |
/* |
| 113 |
TEST_OUTPUT: |
| 114 |
--- |
| 115 |
fail_compilation/fail2456.d(121): Deprecation: can only catch mutable or const qualified types, not `immutable(Exception)` |
| 116 |
--- |
| 117 |
*/ |
| 118 |
void main() { |
| 119 |
try { |
| 120 |
throw new Exception(""); |
| 121 |
} catch (immutable Exception e) { |
| 122 |
assert(0); |
| 123 |
} |
| 124 |
} |