### Eclipse Workspace Patch 1.0 #P org.eclipse.jdt.core.tests.compiler Index: src/org/eclipse/jdt/core/tests/compiler/regression/VarargsTest.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/VarargsTest.java,v retrieving revision 1.42 diff -u -r1.42 VarargsTest.java --- src/org/eclipse/jdt/core/tests/compiler/regression/VarargsTest.java 31 Mar 2006 22:14:20 -0000 1.42 +++ src/org/eclipse/jdt/core/tests/compiler/regression/VarargsTest.java 3 May 2006 16:35:44 -0000 @@ -10,6 +10,10 @@ *******************************************************************************/ package org.eclipse.jdt.core.tests.compiler.regression; +import java.util.Map; + +import org.eclipse.jdt.internal.compiler.impl.CompilerOptions; + import junit.framework.Test; public class VarargsTest extends AbstractComparableTest { @@ -22,7 +26,7 @@ // All specified tests which does not belong to the class are skipped... static { // TESTS_NAMES = new String[] { "test000" }; -// TESTS_NUMBERS = new int[] { 30 }; +// TESTS_NUMBERS = new int[] { 47 }; // TESTS_RANGE = new int[] { 11, -1 }; } public static Test suite() { @@ -1042,8 +1046,8 @@ "}\n", }, "----------\n" + - "1. ERROR in X.java (at line 2)\r\n" + - " transient private X() {}\r\n" + + "1. ERROR in X.java (at line 2)\n" + + " transient private X() {}\n" + " ^^^\n" + "Illegal modifier for the method X.X()\n" + "----------\n" @@ -1249,23 +1253,23 @@ "}\n", }, "----------\n" + - "1. ERROR in X.java (at line 8)\r\n" + - " x.b(true);\r\n" + + "1. ERROR in X.java (at line 8)\n" + + " x.b(true);\n" + " ^\n" + "The method b(boolean, Object[]) is ambiguous for the type X\n" + "----------\n" + - "2. ERROR in X.java (at line 9)\r\n" + - " x.b(true, false);\r\n" + + "2. ERROR in X.java (at line 9)\n" + + " x.b(true, false);\n" + " ^\n" + "The method b(boolean, Object[]) is ambiguous for the type X\n" + "----------\n" + - "3. ERROR in X.java (at line 10)\r\n" + - " x.c(true, true, true);\r\n" + + "3. ERROR in X.java (at line 10)\n" + + " x.c(true, true, true);\n" + " ^\n" + "The method c(boolean, boolean, Object[]) is ambiguous for the type X\n" + "----------\n" + - "4. ERROR in X.java (at line 11)\r\n" + - " x.c(Boolean.TRUE, Boolean.TRUE, Boolean.TRUE);\r\n" + + "4. ERROR in X.java (at line 11)\n" + + " x.c(Boolean.TRUE, Boolean.TRUE, Boolean.TRUE);\n" + " ^\n" + "The method c(boolean, boolean, Object[]) is ambiguous for the type X\n" + "----------\n" @@ -1362,18 +1366,18 @@ "}\n", }, "----------\n" + - "1. ERROR in V.java (at line 4)\r\n" + - " v.foo2(null, \"\");\r\n" + + "1. ERROR in V.java (at line 4)\n" + + " v.foo2(null, \"\");\n" + " ^^^^\n" + "The method foo2(String, Object[]) is ambiguous for the type V\n" + "----------\n" + - "2. ERROR in V.java (at line 5)\r\n" + - " v.foo2(null, \"\", \"\");\r\n" + + "2. ERROR in V.java (at line 5)\n" + + " v.foo2(null, \"\", \"\");\n" + " ^^^^\n" + "The method foo2(String, Object[]) is ambiguous for the type V\n" + "----------\n" + - "3. ERROR in V.java (at line 6)\r\n" + - " v.foo3(\"\", v, null, \"\");\r\n" + + "3. ERROR in V.java (at line 6)\n" + + " v.foo3(\"\", v, null, \"\");\n" + " ^^^^\n" + "The method foo3(String, V, String[]) is ambiguous for the type V\n" + "----------\n"); @@ -1603,13 +1607,13 @@ "}\n", }, "----------\n" + - "1. WARNING in X.java (at line 10)\r\n" + - " array((Serializable[]) new Serializable[] {3, 4}); //warns about unnecessary cast\r\n" + + "1. WARNING in X.java (at line 10)\n" + + " array((Serializable[]) new Serializable[] {3, 4}); //warns about unnecessary cast\n" + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + "Unnecessary cast from Serializable[] to Serializable[]\n" + "----------\n" + - "2. ERROR in X.java (at line 14)\r\n" + - " Zork z;\r\n" + + "2. ERROR in X.java (at line 14)\n" + + " Zork z;\n" + " ^^^^\n" + "Zork cannot be resolved to a type\n" + "----------\n"); @@ -1639,5 +1643,37 @@ " ^^^^\n" + "Zork cannot be resolved to a type\n" + "----------\n"); - } + } + //https://bugs.eclipse.org/bugs/show_bug.cgi?id=139931 + public void test047() { + Map customOptions = getCompilerOptions(); + customOptions.put(CompilerOptions.OPTION_ReportUnnecessaryTypeCheck, CompilerOptions.ERROR); + customOptions.put(CompilerOptions.OPTION_ReportVarargsArgumentNeedCast, CompilerOptions.ERROR); + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " Y [] foo() {\n" + + " return null;\n" + + " }\n" + + " void bar(Y... y) {\n" + + " }\n" + + " void fred() {\n" + + " bar(foo());\n" + + " bar((Y[])foo());\n" + + " }\n" + + "}\n" + + "class Y {\n" + + "}", + }, + "----------\n" + + "1. ERROR in X.java (at line 8)\n" + + " bar(foo());\n" + + " ^^^^^^^^^^\n" + + "The argument of type Y[] should explicitly be cast to Y[] for the invocation of the varargs method bar(Y...) from type X. It could alternatively be cast to Y for a varargs invocation\n" + + "----------\n", + null, + true, + customOptions); + } }