Lines 5609-5612
Link Here
|
5609 |
}, |
5609 |
}, |
5610 |
""); |
5610 |
""); |
5611 |
} |
5611 |
} |
|
|
5612 |
//https://bugs.eclipse.org/bugs/show_bug.cgi?id=255452 |
5613 |
public void test168() { |
5614 |
this.runNegativeTest( |
5615 |
new String[] { |
5616 |
"X.java", // ================= |
5617 |
"enum BadEnum {\n" + |
5618 |
" CRAZY(CRAZY), // <-- illegal forward reference reported by all compilers\n" + |
5619 |
" IMPOSSIBLE(BadEnum.IMPOSSIBLE); // <-- illegal forward reference (javac 1.6 only)\n" + |
5620 |
" private BadEnum(BadEnum self) {\n" + |
5621 |
" }\n" + |
5622 |
"}\n" + |
5623 |
"public class X {\n" + |
5624 |
" X x1 = new X(x1);//1 - WRONG\n" + |
5625 |
" static X X2 = new X(X.X2);//2 - OK\n" + |
5626 |
" X x3 = new X(this.x3);//3 - OK\n" + |
5627 |
" X(X x) {}\n" + |
5628 |
" X(int i) {}\n" + |
5629 |
" static int VALUE() { return 13; }\n" + |
5630 |
" int value() { return 14; }\n" + |
5631 |
"}\n" + |
5632 |
"class Y extends X {\n" + |
5633 |
" X x1 = new X(x1);//6 - WRONG\n" + |
5634 |
" static X X2 = new X(Y.X2);//7 - OK\n" + |
5635 |
" X x3 = new X(this.x3);//8 - OK\n" + |
5636 |
" Y(Y y) { super(y); }\n" + |
5637 |
"}\n", // ================= |
5638 |
}, |
5639 |
"----------\n" + |
5640 |
"1. ERROR in X.java (at line 2)\n" + |
5641 |
" CRAZY(CRAZY), // <-- illegal forward reference reported by all compilers\n" + |
5642 |
" ^^^^^\n" + |
5643 |
"Cannot reference a field before it is defined\n" + |
5644 |
"----------\n" + |
5645 |
"2. ERROR in X.java (at line 3)\n" + |
5646 |
" IMPOSSIBLE(BadEnum.IMPOSSIBLE); // <-- illegal forward reference (javac 1.6 only)\n" + |
5647 |
" ^^^^^^^^^^\n" + |
5648 |
"Cannot reference a field before it is defined\n" + |
5649 |
"----------\n" + |
5650 |
"3. ERROR in X.java (at line 8)\n" + |
5651 |
" X x1 = new X(x1);//1 - WRONG\n" + |
5652 |
" ^^\n" + |
5653 |
"Cannot reference a field before it is defined\n" + |
5654 |
"----------\n" + |
5655 |
"4. WARNING in X.java (at line 17)\n" + |
5656 |
" X x1 = new X(x1);//6 - WRONG\n" + |
5657 |
" ^^\n" + |
5658 |
"The field Y.x1 is hiding a field from type X\n" + |
5659 |
"----------\n" + |
5660 |
"5. ERROR in X.java (at line 17)\n" + |
5661 |
" X x1 = new X(x1);//6 - WRONG\n" + |
5662 |
" ^^\n" + |
5663 |
"Cannot reference a field before it is defined\n" + |
5664 |
"----------\n" + |
5665 |
"6. WARNING in X.java (at line 18)\n" + |
5666 |
" static X X2 = new X(Y.X2);//7 - OK\n" + |
5667 |
" ^^\n" + |
5668 |
"The field Y.X2 is hiding a field from type X\n" + |
5669 |
"----------\n" + |
5670 |
"7. WARNING in X.java (at line 19)\n" + |
5671 |
" X x3 = new X(this.x3);//8 - OK\n" + |
5672 |
" ^^\n" + |
5673 |
"The field Y.x3 is hiding a field from type X\n" + |
5674 |
"----------\n"); |
5675 |
} |
5676 |
//https://bugs.eclipse.org/bugs/show_bug.cgi?id=255452 - variation |
5677 |
public void test169() { |
5678 |
this.runNegativeTest( |
5679 |
new String[] { |
5680 |
"X.java", // ================= |
5681 |
"enum BadEnum {\n" + |
5682 |
" NOWAY(BadEnum.NOWAY.CONST),\n" + |
5683 |
" INVALID(INVALID.CONST),\n" + |
5684 |
" WRONG(WRONG.VALUE()),\n" + |
5685 |
" ILLEGAL(ILLEGAL.value());\n" + |
5686 |
" final static int CONST = 12;\n" + |
5687 |
" private BadEnum(int i) {\n" + |
5688 |
" }\n" + |
5689 |
" static int VALUE() { return 13; }\n" + |
5690 |
" int value() { return 14; }\n" + |
5691 |
"}\n" + |
5692 |
"public class X {\n" + |
5693 |
" final static int CONST = 12;\n" + |
5694 |
" X x4 = new X(x4.CONST);//4 - WRONG\n" + |
5695 |
" X x5 = new X(x5.value());//5 - WRONG\n" + |
5696 |
" X(int i) {}\n" + |
5697 |
" static int VALUE() { return 13; }\n" + |
5698 |
" int value() { return 14; }\n" + |
5699 |
"}\n", // ================= |
5700 |
}, |
5701 |
"----------\n" + |
5702 |
"1. ERROR in X.java (at line 2)\n" + |
5703 |
" NOWAY(BadEnum.NOWAY.CONST),\n" + |
5704 |
" ^^^^^\n" + |
5705 |
"Cannot reference a field before it is defined\n" + |
5706 |
"----------\n" + |
5707 |
"2. ERROR in X.java (at line 2)\n" + |
5708 |
" NOWAY(BadEnum.NOWAY.CONST),\n" + |
5709 |
" ^^^^^\n" + |
5710 |
"Cannot reference a field before it is defined\n" + |
5711 |
"----------\n" + |
5712 |
"3. WARNING in X.java (at line 2)\n" + |
5713 |
" NOWAY(BadEnum.NOWAY.CONST),\n" + |
5714 |
" ^^^^^\n" + |
5715 |
"The static field BadEnum.CONST should be accessed in a static way\n" + |
5716 |
"----------\n" + |
5717 |
"4. ERROR in X.java (at line 3)\n" + |
5718 |
" INVALID(INVALID.CONST),\n" + |
5719 |
" ^^^^^^^\n" + |
5720 |
"Cannot reference a field before it is defined\n" + |
5721 |
"----------\n" + |
5722 |
"5. ERROR in X.java (at line 3)\n" + |
5723 |
" INVALID(INVALID.CONST),\n" + |
5724 |
" ^^^^^\n" + |
5725 |
"Cannot reference a field before it is defined\n" + |
5726 |
"----------\n" + |
5727 |
"6. WARNING in X.java (at line 3)\n" + |
5728 |
" INVALID(INVALID.CONST),\n" + |
5729 |
" ^^^^^\n" + |
5730 |
"The static field BadEnum.CONST should be accessed in a static way\n" + |
5731 |
"----------\n" + |
5732 |
"7. ERROR in X.java (at line 4)\n" + |
5733 |
" WRONG(WRONG.VALUE()),\n" + |
5734 |
" ^^^^^\n" + |
5735 |
"Cannot reference a field before it is defined\n" + |
5736 |
"----------\n" + |
5737 |
"8. WARNING in X.java (at line 4)\n" + |
5738 |
" WRONG(WRONG.VALUE()),\n" + |
5739 |
" ^^^^^^^^^^^^^\n" + |
5740 |
"The static method VALUE() from the type BadEnum should be accessed in a static way\n" + |
5741 |
"----------\n" + |
5742 |
"9. ERROR in X.java (at line 5)\n" + |
5743 |
" ILLEGAL(ILLEGAL.value());\n" + |
5744 |
" ^^^^^^^\n" + |
5745 |
"Cannot reference a field before it is defined\n" + |
5746 |
"----------\n" + |
5747 |
"10. ERROR in X.java (at line 14)\n" + |
5748 |
" X x4 = new X(x4.CONST);//4 - WRONG\n" + |
5749 |
" ^^\n" + |
5750 |
"Cannot reference a field before it is defined\n" + |
5751 |
"----------\n" + |
5752 |
"11. WARNING in X.java (at line 14)\n" + |
5753 |
" X x4 = new X(x4.CONST);//4 - WRONG\n" + |
5754 |
" ^^^^^\n" + |
5755 |
"The static field X.CONST should be accessed in a static way\n" + |
5756 |
"----------\n" + |
5757 |
"12. ERROR in X.java (at line 15)\n" + |
5758 |
" X x5 = new X(x5.value());//5 - WRONG\n" + |
5759 |
" ^^\n" + |
5760 |
"Cannot reference a field before it is defined\n" + |
5761 |
"----------\n"); |
5762 |
} |
5612 |
} |
5763 |
} |