Thu, 03 Feb 2011 09:36:28 +0000
5017953: spurious cascaded diagnostics when name not found
Summary: when an operator is applied to one or more erroneous operands, spurious diagnostics are generated
Reviewed-by: jjg
1 /*
2 * Copyright (c) 1998, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation.
8 *
9 * This code is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12 * version 2 for more details (a copy is included in the LICENSE file that
13 * accompanied this code).
14 *
15 * You should have received a copy of the GNU General Public License version
16 * 2 along with this work; if not, write to the Free Software Foundation,
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 */
24 /*
25 * @test
26 * @bug 4102566
27 * @summary Test access methods for assignment targets.
28 * @author William Maddox (maddox)
29 *
30 * @compile AccessMethodsLHS.java
31 * @run main AccessMethodsLHS
32 */
34 public class AccessMethodsLHS {
36 static void fail(String msg) throws Exception {
37 throw new Exception("FAIL: " + msg);
38 }
40 static int arg = 123456;
42 private int i;
43 private double d;
45 private void m(int x) throws Exception {
46 System.out.println("called AccessMethodsLHS.m");
47 if (x != 123456)
48 AccessMethodsLHS.fail("bad argument");
49 }
51 public static class Bar {
52 private int i;
53 private double d;
54 private String s;
56 private void m(int x) throws Exception {
57 System.out.println("called AccessMethodsLHS.Bar.m");
58 if (x != 123456)
59 AccessMethodsLHS.fail("bad argument");
60 }
62 // Static members are permitted in a static inner class.
64 static private int si;
65 static private double sd;
66 static private String ss;
68 static private void sm(int x) throws Exception {
69 System.out.println("called AccessMethodsLHS.Bar.sm");
70 if (x != 123456)
71 AccessMethodsLHS.fail("bad argument");
72 }
73 }
75 public static class Baz {
76 private int i;
77 private double d;
78 private String s;
80 private void m(int x) throws Exception {
81 System.out.println("called Baz.m");
82 if (x != 123456)
83 AccessMethodsLHS.fail("bad argument");
84 }
86 // Compiler rejects static members here correctly.
88 // static private int si;
89 // static private double sd;
90 // static private String ss;
91 }
93 public class Quux {
94 void DoIt () throws Exception {
95 m(arg);
96 i = 1;
97 d = 1.0;
98 i += 5;
99 i--;
100 }
101 void DoMore(AccessMethodsLHS f) throws Exception {
102 f.m(arg);
103 }
104 }
106 public static class Quem {
107 void DoIt () {
108 // Illegal static refs to non-static vars
109 // i = 1;
110 // d = 1.0;
111 // i += 5;
112 // i--;
113 }
114 }
116 static int effects = 0;
118 static Bar iBar(Bar x) { effects++; return x; }
120 static Baz iBaz(Baz x) { effects++; return x; }
122 static void checkEffects(int i) throws Exception {
123 if (effects != 1) {
124 AccessMethodsLHS.fail("incorrect side-effect behavior (" + effects + "): " + i);
125 }
126 effects = 0;
127 }
129 static public void main(String args[]) throws Exception {
131 Bar b = new Bar();
132 Baz c = new Baz();
134 System.out.println("testing assignment");
136 AccessMethodsLHS f = new AccessMethodsLHS();
138 Quux q1 = f.new Quux();
139 q1.DoIt();
140 q1.DoMore(f);
142 Quem q2 = new Quem();
143 q2.DoIt();
145 // *** Static class, Non-static members ***
147 b.m(arg);
149 // Integer (1 word)
151 b.i = 5;
152 System.out.println(b.i);
153 if (b.i != 5)
154 AccessMethodsLHS.fail("simple assignment");
155 System.out.println(b.i);
158 if ((b.i += 10) != 15)
159 AccessMethodsLHS.fail("add-assign result");
160 System.out.println(b.i);
162 if (b.i != 15)
163 AccessMethodsLHS.fail("add-assign effect");
164 System.out.println(b.i);
166 b.s = "foo";
167 if (!(b.s += "bar").equals("foobar"))
168 AccessMethodsLHS.fail("concat-assign result");
169 System.out.println(b.s);
171 if (!b.s.equals("foobar"))
172 AccessMethodsLHS.fail("concat-assign effect");
173 System.out.println(b.s);
175 b.s = "foo";
176 b.s += "bar";
177 if (!b.s.equals("foobar"))
178 AccessMethodsLHS.fail("concat-assign effect (novalue)");
179 System.out.println(b.s);
181 b.i = 0;
182 b.i++;
183 if (b.i != 1)
184 AccessMethodsLHS.fail("post-increment effect");
185 System.out.println(b.i);
187 b.i = 5;
188 if (b.i++ != 5)
189 AccessMethodsLHS.fail("post-increment result");
190 if (b.i != 6)
191 AccessMethodsLHS.fail("post-increment effect (embedded)");
192 System.out.println(b.i);
194 b.i = 1;
195 --b.i;
196 if (b.i != 0)
197 AccessMethodsLHS.fail("pre-decrement effect");
199 b.i = 5;
200 if (--b.i != 4)
201 AccessMethodsLHS.fail("pre-decrement result");
202 if (b.i != 4)
203 AccessMethodsLHS.fail("pre-decrement effect (embedded)");
204 System.out.println(b.i);
206 // Double (2 word)
208 b.d = 5.0;
209 System.out.println(b.d);
210 if (b.d != 5.0)
211 AccessMethodsLHS.fail("simple assignment");
212 System.out.println(b.d);
214 if ((b.d += 10) != 15.0)
215 AccessMethodsLHS.fail("add-assign result");
216 System.out.println(b.d);
218 if (b.d != 15.0)
219 AccessMethodsLHS.fail("add-assign effect");
220 System.out.println(b.d);
222 b.d = 0.0;
223 b.d++;
224 if (b.d != 1.0)
225 AccessMethodsLHS.fail("post-increment effect");
226 System.out.println(b.d);
228 b.d = 5.0;
229 if (b.d++ != 5.0)
230 AccessMethodsLHS.fail("post-increment result");
231 if (b.d != 6.0)
232 AccessMethodsLHS.fail("post-increment effect (embedded)");
233 System.out.println(b.d);
235 b.d = 1.0;
236 --b.d;
237 if (b.d != 0.0)
238 AccessMethodsLHS.fail("pre-decrement effect");
240 b.d = 5.0;
241 if (--b.d != 4.0)
242 AccessMethodsLHS.fail("pre-decrement result");
243 if (b.d != 4.0)
244 AccessMethodsLHS.fail("pre-decrement effect (embedded)");
245 System.out.println(b.d);
247 // Integer (1 word) with side-effects in object reference
249 iBar(b).i = 5;
250 checkEffects(1);
251 System.out.println(b.i);
252 if (b.i != 5)
253 AccessMethodsLHS.fail("simple assignment");
255 System.out.println(b.i);
257 if ((iBar(b).i += 10) != 15)
258 AccessMethodsLHS.fail("add-assign result");
259 checkEffects(2);
260 System.out.println(b.i);
262 if (b.i != 15)
263 AccessMethodsLHS.fail("add-assign effect");
264 System.out.println(b.i);
266 b.i = 0;
267 iBar(b).i++;
268 checkEffects(3);
269 if (b.i != 1)
270 AccessMethodsLHS.fail("post-increment effect");
271 System.out.println(b.i);
273 b.i = 5;
274 if (iBar(b).i++ != 5)
275 AccessMethodsLHS.fail("post-increment result");
276 checkEffects(4);
277 if (b.i != 6)
278 AccessMethodsLHS.fail("post-increment effect (embedded)");
279 System.out.println(b.i);
281 b.i = 1;
282 --iBar(b).i;
283 checkEffects(5);
284 if (b.i != 0)
285 AccessMethodsLHS.fail("pre-decrement effect");
287 b.i = 5;
288 if (--iBar(b).i != 4)
289 AccessMethodsLHS.fail("pre-decrement result");
290 checkEffects(6);
291 if (b.i != 4)
292 AccessMethodsLHS.fail("pre-decrement effect (embedded)");
293 System.out.println(b.i);
296 // *** Static class, Static members ***
298 Bar.sm(arg);
300 // Integer (1 word)
302 Bar.si = 5;
303 System.out.println(Bar.si);
304 if (Bar.si != 5)
305 AccessMethodsLHS.fail("simple assignment");
306 System.out.println(Bar.si);
308 if ((Bar.si += 10) != 15)
309 AccessMethodsLHS.fail("add-assign result");
310 System.out.println(Bar.si);
312 if (Bar.si != 15)
313 AccessMethodsLHS.fail("add-assign effect");
314 System.out.println(Bar.si);
316 Bar.ss = "foo";
317 if (!(Bar.ss += "bar").equals("foobar"))
318 AccessMethodsLHS.fail("concat-assign result");
319 System.out.println(Bar.ss);
321 if (!Bar.ss.equals("foobar"))
322 AccessMethodsLHS.fail("concat-assign effect");
323 System.out.println(Bar.ss);
325 Bar.ss = "foo";
326 Bar.ss += "bar";
327 if (!Bar.ss.equals("foobar"))
328 AccessMethodsLHS.fail("concat-assign effect (novalue)");
329 System.out.println(Bar.ss);
331 Bar.si = 0;
332 Bar.si++;
333 if (Bar.si != 1)
334 AccessMethodsLHS.fail("post-increment effect");
335 System.out.println(Bar.si);
337 Bar.si = 5;
338 if (Bar.si++ != 5)
339 AccessMethodsLHS.fail("post-increment result");
340 if (Bar.si != 6)
341 AccessMethodsLHS.fail("post-increment effect (embedded)");
342 System.out.println(Bar.si);
344 Bar.si = 1;
345 --Bar.si;
346 if (Bar.si != 0)
347 AccessMethodsLHS.fail("pre-decrement effect");
349 Bar.si = 5;
350 if (--Bar.si != 4)
351 AccessMethodsLHS.fail("pre-decrement result");
352 if (Bar.si != 4)
353 AccessMethodsLHS.fail("pre-decrement effect (embedded)");
354 System.out.println(Bar.si);
356 // Double (2 word)
358 Bar.sd = 5.0;
359 System.out.println(Bar.sd);
360 if (Bar.sd != 5.0)
361 AccessMethodsLHS.fail("simple assignment");
362 System.out.println(Bar.sd);
364 if ((Bar.sd += 10) != 15.0)
365 AccessMethodsLHS.fail("add-assign result");
366 System.out.println(Bar.sd);
368 if (Bar.sd != 15.0)
369 AccessMethodsLHS.fail("add-assign effect");
370 System.out.println(Bar.sd);
372 Bar.sd = 0.0;
373 Bar.sd++;
374 if (Bar.sd != 1.0)
375 AccessMethodsLHS.fail("post-increment effect");
376 System.out.println(Bar.sd);
378 Bar.sd = 5.0;
379 if (Bar.sd++ != 5.0)
380 AccessMethodsLHS.fail("post-increment result");
381 if (Bar.sd != 6.0)
382 AccessMethodsLHS.fail("post-increment effect (embedded)");
383 System.out.println(Bar.sd);
385 Bar.sd = 1.0;
386 --Bar.sd;
387 if (Bar.sd != 0.0)
388 AccessMethodsLHS.fail("pre-decrement effect");
390 Bar.sd = 5.0;
391 if (--Bar.sd != 4.0)
392 AccessMethodsLHS.fail("pre-decrement result");
393 if (Bar.sd != 4.0)
394 AccessMethodsLHS.fail("pre-decrement effect (embedded)");
395 System.out.println(Bar.sd);
398 // *** Static class, Static members (invoked via object reference) ***
400 b.sm(arg);
402 iBar(b).sm(arg);
403 checkEffects(101);
405 // Integer (1 word)
407 b.si = 5;
408 System.out.println(b.si);
409 if (b.si != 5)
410 AccessMethodsLHS.fail("simple assignment");
411 System.out.println(b.si);
413 if ((b.si += 10) != 15)
414 AccessMethodsLHS.fail("add-assign result");
415 System.out.println(b.si);
417 if (b.si != 15)
418 AccessMethodsLHS.fail("add-assign effect");
419 System.out.println(b.si);
421 b.ss = "foo";
422 if (!(b.ss += "bar").equals("foobar"))
423 AccessMethodsLHS.fail("concat-assign result");
424 System.out.println(b.ss);
426 if (!b.ss.equals("foobar"))
427 AccessMethodsLHS.fail("concat-assign effect");
428 System.out.println(b.ss);
430 b.ss = "foo";
431 b.ss += "bar";
432 if (!b.ss.equals("foobar"))
433 AccessMethodsLHS.fail("concat-assign effect (novalue)");
434 System.out.println(b.ss);
436 b.si = 0;
437 b.si++;
438 if (b.si != 1)
439 AccessMethodsLHS.fail("post-increment effect");
440 System.out.println(b.si);
442 b.si = 5;
443 if (b.si++ != 5)
444 AccessMethodsLHS.fail("post-increment result");
445 if (b.si != 6)
446 AccessMethodsLHS.fail("post-increment effect (embedded)");
447 System.out.println(b.si);
449 b.si = 1;
450 --b.si;
451 if (b.si != 0)
452 AccessMethodsLHS.fail("pre-decrement effect");
454 b.si = 5;
455 if (--b.si != 4)
456 AccessMethodsLHS.fail("pre-decrement result");
457 if (b.si != 4)
458 AccessMethodsLHS.fail("pre-decrement effect (embedded)");
459 System.out.println(b.si);
461 // Double (2 word)
463 b.sd = 5.0;
464 System.out.println(b.sd);
465 if (b.sd != 5.0)
466 AccessMethodsLHS.fail("simple assignment");
467 System.out.println(b.sd);
469 if ((b.sd += 10) != 15.0)
470 AccessMethodsLHS.fail("add-assign result");
471 System.out.println(b.sd);
473 if (b.sd != 15.0)
474 AccessMethodsLHS.fail("add-assign effect");
475 System.out.println(b.sd);
477 b.sd = 0.0;
478 b.sd++;
479 if (b.sd != 1.0)
480 AccessMethodsLHS.fail("post-increment effect");
481 System.out.println(b.sd);
483 b.sd = 5.0;
484 if (b.sd++ != 5.0)
485 AccessMethodsLHS.fail("post-increment result");
486 if (b.sd != 6.0)
487 AccessMethodsLHS.fail("post-increment effect (embedded)");
488 System.out.println(b.sd);
490 b.sd = 1.0;
491 --b.sd;
492 if (b.sd != 0.0)
493 AccessMethodsLHS.fail("pre-decrement effect");
495 b.sd = 5.0;
496 if (--b.sd != 4.0)
497 AccessMethodsLHS.fail("pre-decrement result");
498 if (b.sd != 4.0)
499 AccessMethodsLHS.fail("pre-decrement effect (embedded)");
500 System.out.println(b.sd);
502 // Integer (1 word) with side-effects in object reference
504 iBar(b).si = 5;
505 checkEffects(7);
506 System.out.println(b.si);
507 if (b.si != 5)
508 AccessMethodsLHS.fail("simple assignment");
509 System.out.println(b.si);
511 if ((iBar(b).si += 10) != 15)
512 AccessMethodsLHS.fail("add-assign result");
513 checkEffects(8);
514 System.out.println(b.si);
516 if (b.si != 15)
517 AccessMethodsLHS.fail("add-assign effect");
518 System.out.println(b.si);
520 iBar(b).si = 0;
521 checkEffects(9);
522 iBar(b).si++;
523 checkEffects(10);
524 if (b.si != 1)
525 AccessMethodsLHS.fail("post-increment effect");
526 System.out.println(b.si);
528 b.si = 5;
529 if (iBar(b).si++ != 5)
530 AccessMethodsLHS.fail("post-increment result");
531 checkEffects(11);
532 if (b.si != 6)
533 AccessMethodsLHS.fail("post-increment effect (embedded)");
534 System.out.println(b.si);
536 b.si = 1;
537 --iBar(b).si;
538 checkEffects(12);
539 if (b.si != 0)
540 AccessMethodsLHS.fail("pre-decrement effect");
542 b.si = 5;
543 if (--iBar(b).si != 4)
544 AccessMethodsLHS.fail("pre-decrement result");
545 checkEffects(13);
546 if (b.si != 4)
547 AccessMethodsLHS.fail("pre-decrement effect (embedded)");
548 System.out.println(b.si);
551 // *** Non-static class, Non-static members ***
553 c.m(arg);
555 iBaz(c).m(arg);
556 checkEffects(102);
558 // Integer (1 word)
560 c.i = 5;
561 System.out.println(c.i);
562 if (c.i != 5)
563 AccessMethodsLHS.fail("simple assignment");
564 System.out.println(c.i);
566 if ((c.i += 10) != 15)
567 AccessMethodsLHS.fail("add-assign result");
568 System.out.println(c.i);
570 if (c.i != 15)
571 AccessMethodsLHS.fail("add-assign effect");
572 System.out.println(c.i);
574 c.s = "foo";
575 if (!(c.s += "bar").equals("foobar"))
576 AccessMethodsLHS.fail("concat-assign result");
577 System.out.println(c.s);
579 if (!c.s.equals("foobar"))
580 AccessMethodsLHS.fail("concat-assign effect");
581 System.out.println(c.s);
583 c.s = "foo";
584 c.s += "bar";
585 if (!c.s.equals("foobar"))
586 AccessMethodsLHS.fail("concat-assign effect (novalue)");
587 System.out.println(c.s);
589 c.i = 0;
590 c.i++;
591 if (c.i != 1)
592 AccessMethodsLHS.fail("post-increment effect");
593 System.out.println(c.i);
595 c.i = 5;
596 if (c.i++ != 5)
597 AccessMethodsLHS.fail("post-increment result");
598 if (c.i != 6)
599 AccessMethodsLHS.fail("post-increment effect (embedded)");
600 System.out.println(c.i);
602 c.i = 1;
603 --c.i;
604 if (c.i != 0)
605 AccessMethodsLHS.fail("pre-decrement effect");
607 c.i = 5;
608 if (--c.i != 4)
609 AccessMethodsLHS.fail("pre-decrement result");
610 if (c.i != 4)
611 AccessMethodsLHS.fail("pre-decrement effect (embedded)");
612 System.out.println(c.i);
614 // Double (2 word)
616 c.d = 5.0;
617 System.out.println(c.d);
618 if (c.d != 5.0)
619 AccessMethodsLHS.fail("simple assignment");
620 System.out.println(c.d);
622 if ((c.d += 10) != 15.0)
623 AccessMethodsLHS.fail("add-assign result");
624 System.out.println(c.d);
626 if (c.d != 15.0)
627 AccessMethodsLHS.fail("add-assign effect");
628 System.out.println(c.d);
630 c.d = 0.0;
631 c.d++;
632 if (c.d != 1.0)
633 AccessMethodsLHS.fail("post-increment effect");
634 System.out.println(c.d);
636 c.d = 5.0;
637 if (c.d++ != 5.0)
638 AccessMethodsLHS.fail("post-increment result");
639 if (c.d != 6.0)
640 AccessMethodsLHS.fail("post-increment effect (embedded)");
641 System.out.println(c.d);
643 c.d = 1.0;
644 --c.d;
645 if (c.d != 0.0)
646 AccessMethodsLHS.fail("pre-decrement effect");
648 c.d = 5.0;
649 if (--c.d != 4.0)
650 AccessMethodsLHS.fail("pre-decrement result");
651 if (c.d != 4.0)
652 AccessMethodsLHS.fail("pre-decrement effect (embedded)");
653 System.out.println(c.d);
655 // Double (2 word) with side-effects in object reference
657 iBaz(c).d = 5.0;
658 checkEffects(14);
659 System.out.println(c.d);
660 if (c.d != 5.0)
661 AccessMethodsLHS.fail("simple assignment");
662 System.out.println(c.d);
664 if ((iBaz(c).d += 10) != 15.0)
665 AccessMethodsLHS.fail("add-assign result");
666 checkEffects(15);
667 System.out.println(c.d);
669 if (c.d != 15.0)
670 AccessMethodsLHS.fail("add-assign effect");
671 System.out.println(c.d);
673 c.d = 0.0;
674 iBaz(c).d++;
675 checkEffects(16);
676 if (c.d != 1.0)
677 AccessMethodsLHS.fail("post-increment effect");
678 System.out.println(c.d);
680 c.d = 5.0;
681 if (iBaz(c).d++ != 5.0)
682 AccessMethodsLHS.fail("post-increment result");
683 checkEffects(17);
684 if (c.d != 6.0)
685 AccessMethodsLHS.fail("post-increment effect (embedded)");
686 System.out.println(c.d);
688 c.d = 1.0;
689 --iBaz(c).d;
690 checkEffects(18);
691 if (c.d != 0.0)
692 AccessMethodsLHS.fail("pre-decrement effect");
694 c.d = 5.0;
695 if (--iBaz(c).d != 4.0)
696 AccessMethodsLHS.fail("pre-decrement result");
697 checkEffects(19);
698 if (c.d != 4.0)
699 AccessMethodsLHS.fail("pre-decrement effect (embedded)");
700 System.out.println(c.d);
702 // All done.
704 System.out.println("done");
705 }
706 }