| 1 |
/* |
| 2 |
TEST_OUTPUT: |
| 3 |
--- |
| 4 |
fail_compilation/fail302.d(23): Error: cannot implicitly convert expression `1` of type `int` to `Bar` |
| 5 |
fail_compilation/fail302.d(23): `bar = 1` is the first assignment of `bar` therefore it represents its initialization |
| 6 |
fail_compilation/fail302.d(23): `opAssign` methods are not used for initialization, but for subsequent assignments |
| 7 |
--- |
| 8 |
*/ |
| 9 |
|
| 10 |
struct Bar |
| 11 |
{ |
| 12 |
uint num; |
| 13 |
|
| 14 |
Bar opAssign(uint otherNum) |
| 15 |
{ |
| 16 |
num = otherNum; |
| 17 |
return this; |
| 18 |
} |
| 19 |
} |
| 20 |
|
| 21 |
void main() |
| 22 |
{ |
| 23 |
Bar bar = 1; // disallow because construction is not assignment |
| 24 |
auto x = bar.num; |
| 25 |
} |