| 1 |
/* |
| 2 |
REQUIRED_ARGS: -preview=in -preview=dip1000 |
| 3 |
TEST_OUTPUT: |
| 4 |
---- |
| 5 |
fail_compilation/previewin.d(4): Error: function `takeFunction` is not callable using argument types `(void function(real x) pure nothrow @nogc @safe)` |
| 6 |
fail_compilation/previewin.d(4): cannot pass argument `(real x) { }` of type `void function(real x) pure nothrow @nogc @safe` to parameter `void function(in real) f` |
| 7 |
fail_compilation/previewin.d(11): `previewin.takeFunction(void function(in real) f)` declared here |
| 8 |
fail_compilation/previewin.d(5): Error: function `takeFunction` is not callable using argument types `(void function(scope const(real) x) pure nothrow @nogc @safe)` |
| 9 |
fail_compilation/previewin.d(5): cannot pass argument `(scope const(real) x) { }` of type `void function(scope const(real) x) pure nothrow @nogc @safe` to parameter `void function(in real) f` |
| 10 |
fail_compilation/previewin.d(11): `previewin.takeFunction(void function(in real) f)` declared here |
| 11 |
fail_compilation/previewin.d(6): Error: function `takeFunction` is not callable using argument types `(void function(ref scope const(real) x) pure nothrow @nogc @safe)` |
| 12 |
fail_compilation/previewin.d(6): cannot pass argument `(ref scope const(real) x) { }` of type `void function(ref scope const(real) x) pure nothrow @nogc @safe` to parameter `void function(in real) f` |
| 13 |
fail_compilation/previewin.d(11): `previewin.takeFunction(void function(in real) f)` declared here |
| 14 |
fail_compilation/previewin.d(15): Error: assigning scope variable `arg` to global variable `myGlobal` is not allowed in a `@safe` function |
| 15 |
fail_compilation/previewin.d(16): Error: assigning scope variable `arg` to global variable `myGlobal` is not allowed in a `@safe` function |
| 16 |
fail_compilation/previewin.d(17): Error: scope parameter `arg` may not be returned |
| 17 |
fail_compilation/previewin.d(18): Error: assigning scope variable `arg` to `ref` variable `escape` with longer lifetime is not allowed in a `@safe` function |
| 18 |
fail_compilation/previewin.d(22): Error: escaping a reference to parameter `arg` by returning `arg` is not allowed in a `@safe` function |
| 19 |
fail_compilation/previewin.d(22): perhaps annotate the parameter with `return` |
| 20 |
---- |
| 21 |
*/ |
| 22 |
|
| 23 |
#line 1 |
| 24 |
void main () |
| 25 |
{ |
| 26 |
// No covariance without explicit `in` |
| 27 |
takeFunction((real x) {}); |
| 28 |
takeFunction((const scope real x) {}); |
| 29 |
takeFunction((const scope ref real x) {}); |
| 30 |
|
| 31 |
tryEscape("Hello World"); // Yes by `tryEscape` is NG |
| 32 |
} |
| 33 |
|
| 34 |
void takeFunction(void function(in real) f); |
| 35 |
|
| 36 |
// Make sure things cannot be escaped (`scope` is applied) |
| 37 |
const(char)[] myGlobal; |
| 38 |
void tryEscape(in char[] arg) @safe { myGlobal = arg; } |
| 39 |
void tryEscape2(scope const char[] arg) @safe { myGlobal = arg; } |
| 40 |
const(char)[] tryEscape3(in char[] arg) @safe { return arg; } |
| 41 |
void tryEscape4(in char[] arg, ref const(char)[] escape) @safe { escape = arg; } |
| 42 |
// Okay: value type |
| 43 |
ulong[8] tryEscape5(in ulong[8] arg) @safe { return arg; } |
| 44 |
// NG: Ref |
| 45 |
ref const(ulong[8]) tryEscape6(in ulong[8] arg) @safe { return arg; } |