|
2 | 2 | REQUIRED_ARGS: -preview=in -preview=dip1000
|
3 | 3 | TEST_OUTPUT:
|
4 | 4 | ---
|
5 |
| -fail_compilation/previewin.d(3): Error: function `previewin.func1(void function(ulong[8]) dg)` is not callable using argument types `(void function(in ulong[8]))` |
6 |
| -fail_compilation/previewin.d(3): cannot pass argument `& func_byRef` of type `void function(in ulong[8])` to parameter `void function(ulong[8]) dg` |
7 |
| -fail_compilation/previewin.d(4): Error: function `previewin.func2(void function(ref ulong[8]) dg)` is not callable using argument types `(void function(in ulong[8]))` |
8 |
| -fail_compilation/previewin.d(4): cannot pass argument `& func_byRef` of type `void function(in ulong[8])` to parameter `void function(ref ulong[8]) dg` |
9 |
| -fail_compilation/previewin.d(7): Error: function `previewin.func4(void function(ref uint) dg)` is not callable using argument types `(void function(in uint))` |
10 |
| -fail_compilation/previewin.d(7): cannot pass argument `& func_byValue` of type `void function(in uint)` to parameter `void function(ref uint) dg` |
11 |
| -fail_compilation/previewin.d(41): Error: scope variable `arg` assigned to non-scope `myGlobal` |
12 |
| -fail_compilation/previewin.d(42): Error: scope variable `arg` assigned to non-scope `myGlobal` |
13 |
| -fail_compilation/previewin.d(43): Error: scope variable `arg` may not be returned |
14 |
| -fail_compilation/previewin.d(44): Error: scope variable `arg` assigned to `escape` with longer lifetime |
15 |
| -fail_compilation/previewin.d(48): Error: returning `arg` escapes a reference to parameter `arg` |
16 |
| -fail_compilation/previewin.d(48): perhaps annotate the parameter with `return` |
| 5 | +fail_compilation/previewin.d(4): Error: function `previewin.takeFunction(void function(in real) f)` is not callable using argument types `(void function(real x) pure nothrow @nogc @safe)` |
| 6 | +fail_compilation/previewin.d(4): cannot pass argument `__lambda1` of type `void function(real x) pure nothrow @nogc @safe` to parameter `void function(in real) f` |
| 7 | +fail_compilation/previewin.d(5): Error: function `previewin.takeFunction(void function(in real) f)` is not callable using argument types `(void function(const(real) x) pure nothrow @nogc @safe)` |
| 8 | +fail_compilation/previewin.d(5): cannot pass argument `__lambda2` of type `void function(const(real) x) pure nothrow @nogc @safe` to parameter `void function(in real) f` |
| 9 | +fail_compilation/previewin.d(6): Error: function `previewin.takeFunction(void function(in real) f)` is not callable using argument types `(void function(ref const(real) x) pure nothrow @nogc @safe)` |
| 10 | +fail_compilation/previewin.d(6): cannot pass argument `__lambda3` of type `void function(ref const(real) x) pure nothrow @nogc @safe` to parameter `void function(in real) f` |
| 11 | +fail_compilation/previewin.d(15): Error: scope variable `arg` assigned to non-scope `myGlobal` |
| 12 | +fail_compilation/previewin.d(16): Error: scope variable `arg` assigned to non-scope `myGlobal` |
| 13 | +fail_compilation/previewin.d(17): Error: scope variable `arg` may not be returned |
| 14 | +fail_compilation/previewin.d(18): Error: scope variable `arg` assigned to `escape` with longer lifetime |
| 15 | +fail_compilation/previewin.d(22): Error: returning `arg` escapes a reference to parameter `arg` |
| 16 | +fail_compilation/previewin.d(22): perhaps annotate the parameter with `return` |
17 | 17 | ---
|
18 | 18 | */
|
19 | 19 |
|
20 | 20 | #line 1
|
21 | 21 | void main ()
|
22 | 22 | {
|
23 |
| - func1(&func_byRef); // No |
24 |
| - func2(&func_byRef); // No |
25 |
| - func3(&func_byRef); // Could be Yes, but currently No |
26 |
| - |
27 |
| - func4(&func_byValue); // No |
28 |
| - func5(&func_byValue); // Yes |
29 |
| - |
30 |
| - func6(&func_byValue2); // Yes |
31 |
| - func7(&func_byValue3); // Yes |
| 23 | + // No covariance without explicit `in` |
| 24 | + takeFunction((real x) {}); |
| 25 | + takeFunction((const scope real x) {}); |
| 26 | + takeFunction((const scope ref real x) {}); |
32 | 27 |
|
33 | 28 | tryEscape("Hello World"); // Yes by `tryEscape` is NG
|
34 | 29 | }
|
35 | 30 |
|
36 |
| -// Takes by `scope ref const` |
37 |
| -void func_byRef(in ulong[8]) {} |
38 |
| -// Takes by `scope const` |
39 |
| -void func_byValue(in uint) {} |
40 |
| - |
41 |
| -// Error: `ulong[8]` is passed by `ref` |
42 |
| -void func1(void function(scope ulong[8]) dg) {} |
43 |
| -// Error: Missing `scope` on a `ref` |
44 |
| -void func2(void function(ref ulong[8]) dg) {} |
45 |
| -// Works: `scope ref` |
46 |
| -void func3(void function(scope const ref ulong[8]) dg) {} |
47 |
| - |
48 |
| -// Error: `uint` is passed by value |
49 |
| -void func4(void function(ref uint) dg) {} |
50 |
| -// Works: By value `scope const` |
51 |
| -void func5(void function(scope const uint) dg) {} |
52 |
| - |
53 |
| -// This works for arrays: |
54 |
| -void func_byValue2(in char[]) {} |
55 |
| -void func6(void function(char[]) dg) {} |
56 |
| -void func_byValue3(scope const(char)[]) {} |
57 |
| -void func7(void function(in char[]) dg) {} |
| 31 | +void takeFunction(void function(in real) f); |
58 | 32 |
|
59 | 33 | // Make sure things cannot be escaped (`scope` is applied)
|
60 | 34 | const(char)[] myGlobal;
|
|
0 commit comments