View | Details | Raw Unified | Return to bug 251814
Collapse All | Expand All

(-)src/org/eclipse/jdt/core/tests/compiler/regression/EnumTest.java (-37 / +74 lines)
Lines 5828-5834 Link Here
5828
		"1. ERROR in X.java (at line 3)\n" + 
5828
		"1. ERROR in X.java (at line 3)\n" + 
5829
		"	private int valueOf(String arg0) { return 0; }//11\n" + 
5829
		"	private int valueOf(String arg0) { return 0; }//11\n" + 
5830
		"	            ^^^^^^^^^^^^^^^^^^^^\n" + 
5830
		"	            ^^^^^^^^^^^^^^^^^^^^\n" + 
5831
		"The enum X already defines the method valueOf(String) implicitly\n" + 
5831
		"The enum X already defines the method valueOf(String) implicitly\n" +
5832
		"----------\n" +
5833
		"2. ERROR in X.java (at line 5)\n" +
5834
		"	int i = valueOf(\"\");\n" +
5835
		"	        ^^^^^^^^^^^\n" +
5836
		"Type mismatch: cannot convert from X to int\n" + 
5832
		"----------\n",
5837
		"----------\n",
5833
		null,
5838
		null,
5834
		true, // flush output
5839
		true, // flush output
Lines 5838-5856 Link Here
5838
		false);
5843
		false);
5839
	// check for presence of #valueOf(...) in problem type
5844
	// check for presence of #valueOf(...) in problem type
5840
	String expectedOutput =
5845
	String expectedOutput =
5841
		"  // Method descriptor #20 (Ljava/lang/String;)I\n" + 
5846
		"public final enum X {\n" + 
5842
		"  // Stack: 3, Locals: 2\n" + 
5847
		"  \n" + 
5843
		"  private int valueOf(java.lang.String arg0);\n" + 
5848
		"  // Method descriptor #6 (Ljava/lang/String;I)V\n" + 
5849
		"  // Stack: 3, Locals: 3\n" + 
5850
		"  private X(java.lang.String arg0, int arg1);\n" + 
5844
		"     0  new java.lang.Error [8]\n" + 
5851
		"     0  new java.lang.Error [8]\n" + 
5845
		"     3  dup\n" + 
5852
		"     3  dup\n" + 
5846
		"     4  ldc <String \"Unresolved compilation problem: \\n\\tThe enum X already defines the method valueOf(String) implicitly\\n\"> [10]\n" + 
5853
		"     4  ldc <String \"Unresolved compilation problems: \\n\\tThe enum X already defines the method valueOf(String) implicitly\\n\\tType mismatch: cannot convert from X to int\\n\"> [10]\n" + 
5847
		"     6  invokespecial java.lang.Error(java.lang.String) [12]\n" + 
5854
		"     6  invokespecial java.lang.Error(java.lang.String) [12]\n" + 
5848
		"     9  athrow\n" + 
5855
		"     9  athrow\n" + 
5849
		"      Line numbers:\n" + 
5856
		"      Line numbers:\n" + 
5850
		"        [pc: 0, line: 3]\n" + 
5857
		"        [pc: 0, line: 3]\n" + 
5851
		"      Local variable table:\n" + 
5858
		"      Local variable table:\n" + 
5852
		"        [pc: 0, pc: 10] local: this index: 0 type: X\n" + 
5859
		"        [pc: 0, pc: 10] local: this index: 0 type: X\n" + 
5853
		"        [pc: 0, pc: 10] local: arg0 index: 1 type: java.lang.String\n";
5860
		"  \n" + 
5861
		"  // Method descriptor #20 ()V\n" + 
5862
		"  // Stack: 3, Locals: 1\n" + 
5863
		"  void foo();\n" + 
5864
		"     0  new java.lang.Error [8]\n" + 
5865
		"     3  dup\n" + 
5866
		"     4  ldc <String \"Unresolved compilation problem: \\n\\tType mismatch: cannot convert from X to int\\n\"> [21]\n" + 
5867
		"     6  invokespecial java.lang.Error(java.lang.String) [12]\n" + 
5868
		"     9  athrow\n" + 
5869
		"      Line numbers:\n" + 
5870
		"        [pc: 0, line: 5]\n" + 
5871
		"      Local variable table:\n" + 
5872
		"        [pc: 0, pc: 10] local: this index: 0 type: X\n" + 
5873
		"}";
5854
5874
5855
	checkDisassembledClassFile(OUTPUT_DIR + File.separator + "X.class", "X", expectedOutput);
5875
	checkDisassembledClassFile(OUTPUT_DIR + File.separator + "X.class", "X", expectedOutput);
5856
}
5876
}
Lines 5858-5871 Link Here
5858
public void test167() throws Exception {
5878
public void test167() throws Exception {
5859
	this.runNegativeTest(
5879
	this.runNegativeTest(
5860
		new String[] {
5880
		new String[] {
5861
				"X.java", // =================
5881
			"X.java", // =================
5862
				"public enum X {\n" + 
5882
			"public enum X {\n" + 
5863
				"    ;\n" + 
5883
			"    ;\n" + 
5864
				"    static int valueOf(String arg0) { return 0; }//9\n" + 
5884
			"    static int valueOf(String arg0) { return 0; }//9\n" + 
5865
				"    void foo() {\n" + 
5885
			"    void foo() {\n" + 
5866
				"    	int i = X.valueOf(\"\");\n" +
5886
			"    	int i = X.valueOf(\"\");\n" +
5867
				"    }\n" + 
5887
			"    }\n" + 
5868
				"}\n",
5888
			"}\n",
5889
			"Other.java",// =================
5890
			"public class Other {\n" + 
5891
			"    void foo() {\n" + 
5892
			"    	int i = X.valueOf(\"\");\n" + 
5893
			"    }\n" + 
5894
			"}\n", // =================
5895
		},
5896
		"----------\n" + 
5897
		"1. ERROR in X.java (at line 3)\n" +
5898
		"	static int valueOf(String arg0) { return 0; }//9\n" +
5899
		"	           ^^^^^^^^^^^^^^^^^^^^\n" +
5900
		"The enum X already defines the method valueOf(String) implicitly\n" +
5901
		"----------\n" +
5902
		"2. ERROR in X.java (at line 5)\n" +
5903
		"	int i = X.valueOf(\"\");\n" +
5904
		"	        ^^^^^^^^^^^^^\n" +
5905
		"Type mismatch: cannot convert from X to int\n" +
5906
		"----------\n" +
5907
		"----------\n" +
5908
		"1. ERROR in Other.java (at line 3)\n" +
5909
		"	int i = X.valueOf(\"\");\n" +
5910
		"	        ^^^^^^^^^^^^^\n" +
5911
		"Type mismatch: cannot convert from X to int\n" +
5912
		"----------\n",
5913
		null,
5914
		true, // flush output
5915
		null,
5916
		true, // generate output
5917
		false,
5918
		false);
5919
	// check consistency of problem when incremental compiling against X problemType
5920
	this.runNegativeTest(
5921
		new String[] {
5869
				"Other.java",// =================
5922
				"Other.java",// =================
5870
				"public class Other {\n" + 
5923
				"public class Other {\n" + 
5871
				"    void foo() {\n" + 
5924
				"    void foo() {\n" + 
Lines 5873-5905 Link Here
5873
				"    }\n" + 
5926
				"    }\n" + 
5874
				"}\n", // =================
5927
				"}\n", // =================
5875
		},
5928
		},
5876
		"----------\n" + 
5929
		"----------\n" +
5877
		"1. ERROR in X.java (at line 3)\n" + 
5930
		"1. ERROR in Other.java (at line 3)\n" +
5878
		"	static int valueOf(String arg0) { return 0; }//9\n" + 
5931
		"	int i = X.valueOf(\"\");\n" +
5879
		"	           ^^^^^^^^^^^^^^^^^^^^\n" + 
5932
		"	          ^^^^^^^\n" +
5880
		"The enum X already defines the method valueOf(String) implicitly\n" + 
5933
		"The method valueOf(Class<T>, String) in the type Enum<X> is not applicable for the arguments (String)\n" +
5881
		"----------\n",
5934
		"----------\n",
5882
		null,
5935
		null,
5883
		true, // flush output
5936
		false, // flush output
5884
		null,
5937
		null,
5885
		true, // generate output
5938
		true, // generate output
5886
		false,
5939
		false,
5887
		false);
5940
		false);
5888
	// check consistency of problem when incremental compiling against X problemType
5941
	}
5889
	this.runNegativeTest(
5890
			new String[] {
5891
					"Other.java",// =================
5892
					"public class Other {\n" + 
5893
					"    void foo() {\n" + 
5894
					"    	int i = X.valueOf(\"\");\n" + 
5895
					"    }\n" + 
5896
					"}\n", // =================
5897
			},
5898
			"",
5899
			null,
5900
			false, // flush output
5901
			null,
5902
			true, // generate output
5903
			false,
5904
			false);}
5905
}
5942
}
(-)compiler/org/eclipse/jdt/internal/compiler/lookup/SourceTypeBinding.java (-2 / +10 lines)
Lines 1168-1177 Link Here
1168
				if (methodDecl == null) {
1168
				if (methodDecl == null) {
1169
					methodDecl = method.sourceMethod(); // cannot be retrieved after binding is lost & may still be null if method is special
1169
					methodDecl = method.sourceMethod(); // cannot be retrieved after binding is lost & may still be null if method is special
1170
					if (methodDecl != null && methodDecl.binding != null) { // ensure its a valid user defined method
1170
					if (methodDecl != null && methodDecl.binding != null) { // ensure its a valid user defined method
1171
						if (isEnumSpecialMethod)
1171
						if (isEnumSpecialMethod) {
1172
							this.scope.problemReporter().duplicateEnumSpecialMethod(this, methodDecl);
1172
							this.scope.problemReporter().duplicateEnumSpecialMethod(this, methodDecl);
1173
						else
1173
							// remove user defined methods & keep the synthetic
1174
							methodDecl.binding = null;
1175
							// do not alter original method array until resolution is over, due to reentrance (143259)
1176
							if (resolvedMethods == this.methods)
1177
								System.arraycopy(this.methods, 0, resolvedMethods = new MethodBinding[length], 0, length);
1178
							resolvedMethods[i] = null;
1179
							failed++;
1180
						} else {
1174
							this.scope.problemReporter().duplicateMethodInType(this, methodDecl, method.areParametersEqual(method2));
1181
							this.scope.problemReporter().duplicateMethodInType(this, methodDecl, method.areParametersEqual(method2));
1182
						}
1175
					}
1183
					}
1176
				}
1184
				}
1177
				AbstractMethodDeclaration method2Decl = method2.sourceMethod();
1185
				AbstractMethodDeclaration method2Decl = method2.sourceMethod();

Return to bug 251814