| 1 |
/* |
| 2 |
TEST_OUTPUT: |
| 3 |
--- |
| 4 |
fail_compilation/fail13336a.d(28): Error: cannot modify expression `choose(true)` because it is not an lvalue |
| 5 |
--- |
| 6 |
*/ |
| 7 |
|
| 8 |
class Animal {} |
| 9 |
class Cat : Animal {} |
| 10 |
class Dog : Animal {} |
| 11 |
|
| 12 |
Animal animal; |
| 13 |
Cat cat; |
| 14 |
|
| 15 |
auto ref choose(bool f) |
| 16 |
{ |
| 17 |
if (f) |
| 18 |
return cat; |
| 19 |
else |
| 20 |
return animal; |
| 21 |
} |
| 22 |
|
| 23 |
void main() |
| 24 |
{ |
| 25 |
//pragma(msg, typeof(&choose)); |
| 26 |
static assert(is(typeof(&choose) == Animal function(bool) nothrow @nogc @safe)); // pass |
| 27 |
|
| 28 |
choose(true) = new Dog(); |
| 29 |
} |