| 1 |
/// Test storage class inference on delegate parameters |
| 2 |
|
| 3 |
alias FPT = void function (in string, ref string, out string, scope string); |
| 4 |
alias DGT = void delegate (in string, ref string, out string, scope string); |
| 5 |
|
| 6 |
void f1 (FPT func) |
| 7 |
{ |
| 8 |
string ro = "Hello World"; |
| 9 |
string ref_ = ro, out_ = ro; |
| 10 |
func(ro, ref_, out_, ro); |
| 11 |
} |
| 12 |
|
| 13 |
void f2 (DGT func) |
| 14 |
{ |
| 15 |
string ro = "Hello World"; |
| 16 |
string ref_ = ro, out_ = ro; |
| 17 |
func(ro, ref_, out_, ro); |
| 18 |
} |
| 19 |
|
| 20 |
void test () |
| 21 |
{ |
| 22 |
f1((in_, ref_, out_, scope_) { |
| 23 |
assert(in_ == "Hello World"); |
| 24 |
assert(in_ == scope_); |
| 25 |
assert(in_ == ref_); |
| 26 |
assert(out_ is null); |
| 27 |
}); |
| 28 |
|
| 29 |
f2((in_, ref_, out_, scope_) { |
| 30 |
assert(in_ == "Hello World"); |
| 31 |
assert(in_ == scope_); |
| 32 |
assert(in_ == ref_); |
| 33 |
assert(out_ is null); |
| 34 |
}); |
| 35 |
} |
| 36 |
|
| 37 |
// https://issues.dlang.org/show_bug.cgi?id=11316 |
| 38 |
void issue11316() { |
| 39 |
void delegate(const int x) F0; |
| 40 |
F0 = (const int x) {}; // OK |
| 41 |
F0 = (x) {}; // OK |
| 42 |
void delegate(in int x) F1; |
| 43 |
F1 = (in int x) {}; // OK |
| 44 |
F1 = (x) {}; // OK |
| 45 |
void delegate(ref int x) F2; |
| 46 |
F2 = (ref int x) {}; // OK |
| 47 |
F2 = (x) {}; // Error |
| 48 |
void delegate(out int x) F3; |
| 49 |
F3 = (out int x) {}; // OK |
| 50 |
F3 = (x) {}; // Error |
| 51 |
} |