### Eclipse Workspace Patch 1.0 #P org.eclipse.jdt.core.tests.compiler Index: src/org/eclipse/jdt/core/tests/compiler/regression/AssignmentTest.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/AssignmentTest.java,v retrieving revision 1.40 diff -u -r1.40 AssignmentTest.java --- src/org/eclipse/jdt/core/tests/compiler/regression/AssignmentTest.java 1 Jun 2007 08:26:25 -0000 1.40 +++ src/org/eclipse/jdt/core/tests/compiler/regression/AssignmentTest.java 17 Oct 2007 11:47:56 -0000 @@ -33,7 +33,7 @@ // All specified tests which does not belong to the class are skipped... static { // TESTS_NAMES = new String[] { "test000" }; -// TESTS_NUMBERS = new int[] { 45 }; +// TESTS_NUMBERS = new int[] { 2, 46, 47 }; // TESTS_RANGE = new int[] { 11, -1 }; } public static Test suite() { @@ -1102,6 +1102,126 @@ "The assignment to variable length3 has no effect\n" + "----------\n"); } +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=200724 +public void test046() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " public static String s;\n" + + " void foo(String s1) {\n" + + " X.s = s;" + + " }\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in X.java (at line 4)\n" + + " X.s = s; }\n" + + " ^^^^^^^\n" + + "The assignment to variable s has no effect\n" + + "----------\n"); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=200724 +public void test047() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " public static X MyX;\n" + + " public static String s;\n" + + " void foo(String s1) {\n" + + " X.MyX.s = s;" + // MyX could hold any extending type, hence we must not complain + " }\n" + + "}\n", + }, + ""); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=200724 +// we could decide that MyX won't change, hence that the assignment +// on line a has no effect, but we accept this as a limit +public void _test048() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " public static final X MyX = new X();\n" + + " public static String s;\n" + + " void foo(String s1) {\n" + + " X.MyX.s = s;" + // a + " }\n" + + "}\n", + }, + "ERR"); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=200724 +// adding a package to the picture +public void test049() { + this.runNegativeTest( + new String[] { + "p/X.java", + "package p;\n" + + "public class X {\n" + + " public static String s;\n" + + " void foo(String s1) {\n" + + " p.X.s = s;" + + " }\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in p\\X.java (at line 5)\n" + + " p.X.s = s; }\n" + + " ^^^^^^^^^\n" + + "The assignment to variable s has no effect\n" + + "----------\n"); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=200724 +// adding an inner class to the picture +public void test050() { + this.runNegativeTest( + new String[] { + "p/X.java", + "package p;\n" + + "public class X {\n" + + " class XX {\n" + + " public static String s;\n" + + " void foo(String s1) {\n" + + " X.XX.s = s;" + + " }\n" + + " }\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in p\\X.java (at line 4)\n" + + " public static String s;\n" + + " ^\n" + + "The field s cannot be declared static; static fields can only be declared in static or top level types\n" + + "----------\n" + + "2. ERROR in p\\X.java (at line 6)\n" + + " X.XX.s = s; }\n" + + " ^^^^^^^^^^\n" + + "The assignment to variable s has no effect\n" + + "----------\n"); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=200724 +// swap lhs and rhs +public void test051() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " public static String s;\n" + + " void foo(String s1) {\n" + + " s = X.s;" + + " }\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in X.java (at line 4)\n" + + " s = X.s; }\n" + + " ^^^^^^^\n" + + "The assignment to variable s has no effect\n" + + "----------\n"); +} public static Class testClass() { return AssignmentTest.class; } #P org.eclipse.jdt.core Index: compiler/org/eclipse/jdt/internal/compiler/ast/Assignment.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/Assignment.java,v retrieving revision 1.79 diff -u -r1.79 Assignment.java --- compiler/org/eclipse/jdt/internal/compiler/ast/Assignment.java 24 Sep 2007 22:49:54 -0000 1.79 +++ compiler/org/eclipse/jdt/internal/compiler/ast/Assignment.java 17 Oct 2007 11:48:03 -0000 @@ -118,6 +118,13 @@ // i = i++; // eq to ++i; return getDirectBinding (((Assignment)someExpression).lhs); } + } else if (someExpression instanceof QualifiedNameReference) { + QualifiedNameReference qualifiedNameReference = (QualifiedNameReference) someExpression; + if (qualifiedNameReference.indexOfFirstFieldBinding != 1 + && qualifiedNameReference.otherBindings == null) { + // case where a static field is retrieved using ClassName.fieldname + return qualifiedNameReference.binding; + } } // } else if (someExpression instanceof PostfixExpression) { // recurse for postfix: i++ --> i // // note: "b = b++" is equivalent to doing nothing, not to "b++"