]>
Commit | Line | Data |
---|---|---|
b4c522fa IB |
1 | /* |
2 | TEST_OUTPUT: | |
3 | --- | |
4 | fail_compilation/diag10862.d(28): Error: assignment cannot be used as a condition, perhaps `==` was meant? | |
5 | fail_compilation/diag10862.d(29): Error: assignment cannot be used as a condition, perhaps `==` was meant? | |
6 | fail_compilation/diag10862.d(30): Error: assignment cannot be used as a condition, perhaps `==` was meant? | |
7 | fail_compilation/diag10862.d(31): Error: assignment cannot be used as a condition, perhaps `==` was meant? | |
8 | fail_compilation/diag10862.d(32): Error: assignment cannot be used as a condition, perhaps `==` was meant? | |
9 | fail_compilation/diag10862.d(34): Error: assignment cannot be used as a condition, perhaps `==` was meant? | |
10 | fail_compilation/diag10862.d(35): Error: assignment cannot be used as a condition, perhaps `==` was meant? | |
11 | fail_compilation/diag10862.d(36): Error: assignment cannot be used as a condition, perhaps `==` was meant? | |
12 | fail_compilation/diag10862.d(37): Error: assignment cannot be used as a condition, perhaps `==` was meant? | |
13 | fail_compilation/diag10862.d(39): Error: assignment cannot be used as a condition, perhaps `==` was meant? | |
14 | fail_compilation/diag10862.d(40): Error: assignment cannot be used as a condition, perhaps `==` was meant? | |
15 | fail_compilation/diag10862.d(41): Error: assignment cannot be used as a condition, perhaps `==` was meant? | |
16 | fail_compilation/diag10862.d(42): Error: assignment cannot be used as a condition, perhaps `==` was meant? | |
17 | fail_compilation/diag10862.d(44): Error: assignment cannot be used as a condition, perhaps `==` was meant? | |
18 | fail_compilation/diag10862.d(45): Error: assignment cannot be used as a condition, perhaps `==` was meant? | |
19 | fail_compilation/diag10862.d(46): Error: assignment cannot be used as a condition, perhaps `==` was meant? | |
20 | fail_compilation/diag10862.d(47): Error: assignment cannot be used as a condition, perhaps `==` was meant? | |
21 | fail_compilation/diag10862.d(49): Error: undefined identifier `semanticError` | |
22 | --- | |
23 | */ | |
24 | void test1() | |
25 | { | |
26 | int a, b; | |
27 | ||
28 | if (a = b) {} | |
29 | if ((a = b) = 0) {} | |
30 | if ((a = b) = (a = b)) {} | |
31 | if (a = 0, b = 0) {} // Bugzilla 15384 | |
32 | if (auto x = a = b) {} // this is error, today | |
33 | ||
34 | while (a = b) {} | |
35 | while ((a = b) = 0) {} | |
36 | while ((a = b) = (a = b)) {} | |
37 | while (a = 0, b = 0) {} // Bugzilla 15384 | |
38 | ||
39 | do {} while (a = b); | |
40 | do {} while ((a = b) = 0); | |
41 | do {} while ((a = b) = (a = b)); | |
42 | do {} while (a = 0, b = 0); // Bugzilla 15384 | |
43 | ||
44 | for (; a = b; ) {} | |
45 | for (; (a = b) = 0; ) {} | |
46 | for (; (a = b) = (a = b); ) {} | |
47 | for (; a = 0, b = 0; ) {} // Bugzilla 15384 | |
48 | ||
49 | semanticError; | |
50 | } | |
51 | ||
52 | /* | |
53 | TEST_OUTPUT: | |
54 | --- | |
55 | fail_compilation/diag10862.d(74): Error: assignment cannot be used as a condition, perhaps `==` was meant? | |
56 | fail_compilation/diag10862.d(77): Error: assignment cannot be used as a condition, perhaps `==` was meant? | |
57 | fail_compilation/diag10862.d-mixin-80(80): Error: assignment cannot be used as a condition, perhaps == was meant? | |
58 | fail_compilation/diag10862.d-mixin-81(81): Error: assignment cannot be used as a condition, perhaps == was meant? | |
59 | fail_compilation/diag10862.d-mixin-82(82): Error: assignment cannot be used as a condition, perhaps == was meant? | |
60 | fail_compilation/diag10862.d-mixin-83(83): Deprecation: Using the result of a comma expression is deprecated | |
61 | fail_compilation/diag10862.d-mixin-83(83): Error: assignment cannot be used as a condition, perhaps == was meant? | |
62 | fail_compilation/diag10862.d-mixin-86(86): Error: a + b is not an lvalue | |
63 | fail_compilation/diag10862.d-mixin-87(87): Error: undefined identifier `c` | |
64 | fail_compilation/diag10862.d(89): Error: undefined identifier `semanticError` | |
65 | --- | |
66 | */ | |
67 | void test2() | |
68 | { | |
69 | int a, b; | |
70 | ||
71 | // (a + b) cannot be an assignment target. | |
72 | // However checkAssignAsCondition specilatively rerites it to EqualExp, | |
73 | // then the pointless error "is not an lvalue" would not happen. | |
74 | if (a + b = a * b) {} | |
75 | ||
76 | // The suggestion error masks "undefined identifier" error | |
77 | if (a = undefinedIdentifier) {} | |
78 | ||
79 | // If the condition is a mixin expression | |
80 | if (mixin("a = b")) {} | |
81 | if (mixin("(a = b) = 0")) {} | |
82 | if (mixin("(a = b) = (a = b)")) {} | |
83 | if (mixin("a = 0, b = 0")) {} | |
84 | if (auto x = mixin("a = b")) {} // Note: no error | |
85 | ||
86 | if (mixin("a + b = a * b")) {} // Note: "a + b is not an lvalue" | |
87 | if (mixin("a = c")) {} | |
88 | ||
89 | semanticError; | |
90 | } |