View | Details | Raw Unified | Return to bug 139931 | Differences between
and this patch

Collapse All | Expand All

(-)src/org/eclipse/jdt/core/tests/compiler/regression/VarargsTest.java (-22 / +58 lines)
Lines 10-15 Link Here
10
 *******************************************************************************/
10
 *******************************************************************************/
11
package org.eclipse.jdt.core.tests.compiler.regression;
11
package org.eclipse.jdt.core.tests.compiler.regression;
12
12
13
import java.util.Map;
14
15
import org.eclipse.jdt.internal.compiler.impl.CompilerOptions;
16
13
import junit.framework.Test;
17
import junit.framework.Test;
14
18
15
public class VarargsTest extends AbstractComparableTest {
19
public class VarargsTest extends AbstractComparableTest {
Lines 22-28 Link Here
22
	// All specified tests which does not belong to the class are skipped...
26
	// All specified tests which does not belong to the class are skipped...
23
	static {
27
	static {
24
//		TESTS_NAMES = new String[] { "test000" };
28
//		TESTS_NAMES = new String[] { "test000" };
25
//		TESTS_NUMBERS = new int[] { 30 };
29
//		TESTS_NUMBERS = new int[] { 47 };
26
//		TESTS_RANGE = new int[] { 11, -1 };
30
//		TESTS_RANGE = new int[] { 11, -1 };
27
	}
31
	}
28
	public static Test suite() {
32
	public static Test suite() {
Lines 1042-1049 Link Here
1042
				"}\n",
1046
				"}\n",
1043
			},
1047
			},
1044
			"----------\n" + 
1048
			"----------\n" + 
1045
			"1. ERROR in X.java (at line 2)\r\n" + 
1049
			"1. ERROR in X.java (at line 2)\n" + 
1046
			"	transient private X() {}\r\n" + 
1050
			"	transient private X() {}\n" + 
1047
			"	                  ^^^\n" + 
1051
			"	                  ^^^\n" + 
1048
			"Illegal modifier for the method X.X()\n" + 
1052
			"Illegal modifier for the method X.X()\n" + 
1049
			"----------\n"
1053
			"----------\n"
Lines 1249-1271 Link Here
1249
				"}\n",
1253
				"}\n",
1250
			},
1254
			},
1251
			"----------\n" + 
1255
			"----------\n" + 
1252
			"1. ERROR in X.java (at line 8)\r\n" + 
1256
			"1. ERROR in X.java (at line 8)\n" + 
1253
			"	x.b(true);\r\n" + 
1257
			"	x.b(true);\n" + 
1254
			"	  ^\n" + 
1258
			"	  ^\n" + 
1255
			"The method b(boolean, Object[]) is ambiguous for the type X\n" + 
1259
			"The method b(boolean, Object[]) is ambiguous for the type X\n" + 
1256
			"----------\n" + 
1260
			"----------\n" + 
1257
			"2. ERROR in X.java (at line 9)\r\n" + 
1261
			"2. ERROR in X.java (at line 9)\n" + 
1258
			"	x.b(true, false);\r\n" + 
1262
			"	x.b(true, false);\n" + 
1259
			"	  ^\n" + 
1263
			"	  ^\n" + 
1260
			"The method b(boolean, Object[]) is ambiguous for the type X\n" + 
1264
			"The method b(boolean, Object[]) is ambiguous for the type X\n" + 
1261
			"----------\n" + 
1265
			"----------\n" + 
1262
			"3. ERROR in X.java (at line 10)\r\n" + 
1266
			"3. ERROR in X.java (at line 10)\n" + 
1263
			"	x.c(true, true, true);\r\n" + 
1267
			"	x.c(true, true, true);\n" + 
1264
			"	  ^\n" + 
1268
			"	  ^\n" + 
1265
			"The method c(boolean, boolean, Object[]) is ambiguous for the type X\n" + 
1269
			"The method c(boolean, boolean, Object[]) is ambiguous for the type X\n" + 
1266
			"----------\n" + 
1270
			"----------\n" + 
1267
			"4. ERROR in X.java (at line 11)\r\n" + 
1271
			"4. ERROR in X.java (at line 11)\n" + 
1268
			"	x.c(Boolean.TRUE, Boolean.TRUE, Boolean.TRUE);\r\n" + 
1272
			"	x.c(Boolean.TRUE, Boolean.TRUE, Boolean.TRUE);\n" + 
1269
			"	  ^\n" + 
1273
			"	  ^\n" + 
1270
			"The method c(boolean, boolean, Object[]) is ambiguous for the type X\n" + 
1274
			"The method c(boolean, boolean, Object[]) is ambiguous for the type X\n" + 
1271
			"----------\n"
1275
			"----------\n"
Lines 1362-1379 Link Here
1362
				"}\n",
1366
				"}\n",
1363
			},
1367
			},
1364
			"----------\n" + 
1368
			"----------\n" + 
1365
			"1. ERROR in V.java (at line 4)\r\n" + 
1369
			"1. ERROR in V.java (at line 4)\n" + 
1366
			"	v.foo2(null, \"\");\r\n" + 
1370
			"	v.foo2(null, \"\");\n" + 
1367
			"	  ^^^^\n" + 
1371
			"	  ^^^^\n" + 
1368
			"The method foo2(String, Object[]) is ambiguous for the type V\n" + 
1372
			"The method foo2(String, Object[]) is ambiguous for the type V\n" + 
1369
			"----------\n" + 
1373
			"----------\n" + 
1370
			"2. ERROR in V.java (at line 5)\r\n" + 
1374
			"2. ERROR in V.java (at line 5)\n" + 
1371
			"	v.foo2(null, \"\", \"\");\r\n" + 
1375
			"	v.foo2(null, \"\", \"\");\n" + 
1372
			"	  ^^^^\n" + 
1376
			"	  ^^^^\n" + 
1373
			"The method foo2(String, Object[]) is ambiguous for the type V\n" + 
1377
			"The method foo2(String, Object[]) is ambiguous for the type V\n" + 
1374
			"----------\n" + 
1378
			"----------\n" + 
1375
			"3. ERROR in V.java (at line 6)\r\n" + 
1379
			"3. ERROR in V.java (at line 6)\n" + 
1376
			"	v.foo3(\"\", v, null, \"\");\r\n" + 
1380
			"	v.foo3(\"\", v, null, \"\");\n" + 
1377
			"	  ^^^^\n" + 
1381
			"	  ^^^^\n" + 
1378
			"The method foo3(String, V, String[]) is ambiguous for the type V\n" + 
1382
			"The method foo3(String, V, String[]) is ambiguous for the type V\n" + 
1379
			"----------\n");
1383
			"----------\n");
Lines 1603-1615 Link Here
1603
					"}\n",
1607
					"}\n",
1604
				},
1608
				},
1605
				"----------\n" + 
1609
				"----------\n" + 
1606
				"1. WARNING in X.java (at line 10)\r\n" + 
1610
				"1. WARNING in X.java (at line 10)\n" + 
1607
				"	array((Serializable[]) new Serializable[] {3, 4}); //warns about unnecessary cast\r\n" + 
1611
				"	array((Serializable[]) new Serializable[] {3, 4}); //warns about unnecessary cast\n" + 
1608
				"	      ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + 
1612
				"	      ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + 
1609
				"Unnecessary cast from Serializable[] to Serializable[]\n" + 
1613
				"Unnecessary cast from Serializable[] to Serializable[]\n" + 
1610
				"----------\n" + 
1614
				"----------\n" + 
1611
				"2. ERROR in X.java (at line 14)\r\n" + 
1615
				"2. ERROR in X.java (at line 14)\n" + 
1612
				"	Zork z;\r\n" + 
1616
				"	Zork z;\n" + 
1613
				"	^^^^\n" + 
1617
				"	^^^^\n" + 
1614
				"Zork cannot be resolved to a type\n" + 
1618
				"Zork cannot be resolved to a type\n" + 
1615
				"----------\n");
1619
				"----------\n");
Lines 1639-1643 Link Here
1639
				"	^^^^\n" + 
1643
				"	^^^^\n" + 
1640
				"Zork cannot be resolved to a type\n" + 
1644
				"Zork cannot be resolved to a type\n" + 
1641
				"----------\n");
1645
				"----------\n");
1642
	}	
1646
	}
1647
	//https://bugs.eclipse.org/bugs/show_bug.cgi?id=139931
1648
	public void test047() {
1649
		Map customOptions = getCompilerOptions();
1650
		customOptions.put(CompilerOptions.OPTION_ReportUnnecessaryTypeCheck, CompilerOptions.ERROR);
1651
		customOptions.put(CompilerOptions.OPTION_ReportVarargsArgumentNeedCast, CompilerOptions.ERROR);
1652
		this.runNegativeTest(
1653
				new String[] {
1654
					"X.java",
1655
					"public class X {\n" + 
1656
					"        Y<?> [] foo() {\n" + 
1657
					"                return null;\n" + 
1658
					"        }\n" + 
1659
					"        void bar(Y... y) {\n" + 
1660
					"        }\n" + 
1661
					"        void fred() {\n" + 
1662
					"                bar(foo());\n" + 
1663
					"                bar((Y[])foo());\n" + 
1664
					"        }\n" + 
1665
					"}\n" + 
1666
					"class Y<E> {\n" + 
1667
					"}",
1668
				},
1669
				"----------\n" + 
1670
				"1. ERROR in X.java (at line 8)\n" + 
1671
				"	bar(foo());\n" + 
1672
				"	^^^^^^^^^^\n" + 
1673
				"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" + 
1674
				"----------\n",
1675
				null,
1676
				true,
1677
				customOptions);
1678
	}
1643
}
1679
}

Return to bug 139931