Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
View | Details | Raw Unified | Return to bug 345559 | Differences between
and this patch

Collapse All | Expand All

(-)compiler/org/eclipse/jdt/internal/compiler/ast/AllocationExpression.java (-8 / +5 lines)
Lines 17-23 Link Here
17
 *******************************************************************************/
17
 *******************************************************************************/
18
package org.eclipse.jdt.internal.compiler.ast;
18
package org.eclipse.jdt.internal.compiler.ast;
19
19
20
import org.eclipse.jdt.core.compiler.CharOperation;
21
import org.eclipse.jdt.internal.compiler.ASTVisitor;
20
import org.eclipse.jdt.internal.compiler.ASTVisitor;
22
import org.eclipse.jdt.internal.compiler.classfmt.ClassFileConstants;
21
import org.eclipse.jdt.internal.compiler.classfmt.ClassFileConstants;
23
import org.eclipse.jdt.internal.compiler.codegen.*;
22
import org.eclipse.jdt.internal.compiler.codegen.*;
Lines 375-380 Link Here
375
	}
374
	}
376
	if (isDiamond) {
375
	if (isDiamond) {
377
		TypeBinding [] inferredTypes = inferElidedTypes(((ParameterizedTypeBinding) this.resolvedType).genericType(), argumentTypes, scope);
376
		TypeBinding [] inferredTypes = inferElidedTypes(((ParameterizedTypeBinding) this.resolvedType).genericType(), argumentTypes, scope);
377
		if (inferredTypes == null) {
378
			scope.problemReporter().cannotInferElidedTypes(this);
379
			return this.resolvedType = null;
380
		}
378
		this.resolvedType = this.type.resolvedType = scope.environment().createParameterizedType(((ParameterizedTypeBinding) this.resolvedType).genericType(), inferredTypes, ((ParameterizedTypeBinding) this.resolvedType).enclosingType());
381
		this.resolvedType = this.type.resolvedType = scope.environment().createParameterizedType(((ParameterizedTypeBinding) this.resolvedType).genericType(), inferredTypes, ((ParameterizedTypeBinding) this.resolvedType).enclosingType());
379
 	}
382
 	}
380
	ReferenceBinding allocationType = (ReferenceBinding) this.resolvedType;
383
	ReferenceBinding allocationType = (ReferenceBinding) this.resolvedType;
Lines 412-424 Link Here
412
	if (factory instanceof ParameterizedGenericMethodBinding && factory.isValidBinding()) {
415
	if (factory instanceof ParameterizedGenericMethodBinding && factory.isValidBinding()) {
413
		return ((ParameterizedTypeBinding)factory.returnType).arguments;
416
		return ((ParameterizedTypeBinding)factory.returnType).arguments;
414
	}
417
	}
415
	scope.problemReporter().cannotInferElidedTypes(this);
418
	return null;
416
	int arity = allocationType.typeVariables().length;
417
	TypeBinding [] inferredTypes = new TypeBinding[arity];
418
	for (int i = 0; i < arity; i++) {
419
		inferredTypes[i] = new ProblemReferenceBinding(CharOperation.NO_CHAR_CHAR, null, ProblemReasons.InferenceFailed);
420
	}
421
	return inferredTypes;
422
}
419
}
423
420
424
public void setActualReceiverType(ReferenceBinding receiverType) {
421
public void setActualReceiverType(ReferenceBinding receiverType) {
(-)compiler/org/eclipse/jdt/internal/compiler/ast/QualifiedAllocationExpression.java (+4 lines)
Lines 400-405 Link Here
400
			}
400
			}
401
			if (isDiamond) {
401
			if (isDiamond) {
402
				TypeBinding [] inferredTypes = inferElidedTypes(((ParameterizedTypeBinding) receiverType).genericType(), argumentTypes, scope);
402
				TypeBinding [] inferredTypes = inferElidedTypes(((ParameterizedTypeBinding) receiverType).genericType(), argumentTypes, scope);
403
				if (inferredTypes == null) {
404
					scope.problemReporter().cannotInferElidedTypes(this);
405
					return this.resolvedType = null;
406
				}
403
				receiverType = this.type.resolvedType = scope.environment().createParameterizedType(((ParameterizedTypeBinding) receiverType).genericType(), inferredTypes, ((ParameterizedTypeBinding) receiverType).enclosingType());
407
				receiverType = this.type.resolvedType = scope.environment().createParameterizedType(((ParameterizedTypeBinding) receiverType).genericType(), inferredTypes, ((ParameterizedTypeBinding) receiverType).enclosingType());
404
			}
408
			}
405
			ReferenceBinding allocationType = (ReferenceBinding) receiverType;
409
			ReferenceBinding allocationType = (ReferenceBinding) receiverType;
(-)compiler/org/eclipse/jdt/internal/compiler/lookup/ProblemReasons.java (-1 lines)
Lines 31-35 Link Here
31
	final int TypeArgumentsForRawGenericMethod = 13; // for generic method
31
	final int TypeArgumentsForRawGenericMethod = 13; // for generic method
32
	final int InvalidTypeForStaticImport = 14;
32
	final int InvalidTypeForStaticImport = 14;
33
	final int InvalidTypeForAutoManagedResource = 15;
33
	final int InvalidTypeForAutoManagedResource = 15;
34
	final int InferenceFailed = 16;
35
}
34
}
(-)compiler/org/eclipse/jdt/internal/compiler/lookup/Scope.java (-1 / +7 lines)
Lines 4036-4042 Link Here
4036
		int sfi = 0;
4036
		int sfi = 0;
4037
		for (int i = 0, length = methods.length; i < length; i++) {
4037
		for (int i = 0, length = methods.length; i < length; i++) {
4038
			MethodBinding method = methods[i];
4038
			MethodBinding method = methods[i];
4039
			
4039
			int paramLength = method.parameters.length;
4040
			boolean isVarArgs = method.isVarargs();
4041
			if (argumentTypes.length != paramLength)
4042
				if (!isVarArgs || argumentTypes.length < paramLength - 1)
4043
					continue; // incompatible
4040
			TypeVariableBinding[] methodTypeVariables = method.typeVariables();
4044
			TypeVariableBinding[] methodTypeVariables = method.typeVariables();
4041
			int methodTypeVariablesArity = methodTypeVariables.length;
4045
			int methodTypeVariablesArity = methodTypeVariables.length;
4042
	        
4046
	        
Lines 4114-4119 Link Here
4114
			staticFactories[sfi++] = new ParameterizedMethodBinding((ParameterizedTypeBinding) environment.convertToParameterizedType(staticFactory.declaringClass),
4118
			staticFactories[sfi++] = new ParameterizedMethodBinding((ParameterizedTypeBinding) environment.convertToParameterizedType(staticFactory.declaringClass),
4115
																												staticFactory);
4119
																												staticFactory);
4116
		}
4120
		}
4121
		if (sfi == 0)
4122
			return null;
4117
		if (sfi != methods.length) {
4123
		if (sfi != methods.length) {
4118
			System.arraycopy(staticFactories, 0, staticFactories = new MethodBinding[sfi], 0, sfi);
4124
			System.arraycopy(staticFactories, 0, staticFactories = new MethodBinding[sfi], 0, sfi);
4119
		}
4125
		}
(-)src/org/eclipse/jdt/core/tests/compiler/regression/GenericsRegressionTest_1_7.java (-10 / +254 lines)
Lines 991-1006 Link Here
991
		"	Map<String, Integer> m1 = new StringKeyHashMap<>(10);\n" + 
991
		"	Map<String, Integer> m1 = new StringKeyHashMap<>(10);\n" + 
992
		"	                          ^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + 
992
		"	                          ^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + 
993
		"Cannot infer elided type(s)\n" + 
993
		"Cannot infer elided type(s)\n" + 
994
		"----------\n" + 
995
		"4. ERROR in X.java (at line 11)\n" + 
996
		"	Map<String, Integer> m1 = new StringKeyHashMap<>(10);\n" + 
997
		"	                          ^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + 
998
		"The constructor StringKeyHashMap<>(int) is undefined\n" + 
999
		"----------\n" + 
1000
		"5. ERROR in X.java (at line 11)\n" + 
1001
		"	Map<String, Integer> m1 = new StringKeyHashMap<>(10);\n" + 
1002
		"	                          ^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + 
1003
		"Type mismatch: cannot convert from StringKeyHashMap<> to Map<String,Integer>\n" + 
1004
		"----------\n");
994
		"----------\n");
1005
}
995
}
1006
// check inference at return expression.
996
// check inference at return expression.
Lines 1198-1203 Link Here
1198
		"Y cannot be resolved to a type\n" + 
1188
		"Y cannot be resolved to a type\n" + 
1199
		"----------\n");
1189
		"----------\n");
1200
}
1190
}
1191
// https://bugs.eclipse.org/bugs/show_bug.cgi?id=345559
1192
// TODO(ayush) enable and update the error message after bug 345968 is fixed
1193
public void _test0031() {
1194
	this.runNegativeTest(
1195
		new String[] {
1196
			"X.java",
1197
			"public class X<T>  {\n" +
1198
			"    X(T t) {}\n" +
1199
			"    X() {}\n" +
1200
			"    void foo(T a) {\n" +
1201
			"	 System.out.println(a);\n" +
1202
			"	 }\n" +
1203
			"	 class Y<K>{\n" +
1204
			"		Y(T t,K k) {}\n" +
1205
			"	 }\n" +
1206
			"    public static void main(String[] args) {\n" +
1207
			"		X<Integer> x1 = new X<>(1,1);\n" +
1208
			"		X<Integer> x2 = new X<>(1);\n" +
1209
			"		X<Integer> x3 = new X<>();\n" +
1210
			"		X<Integer>.Y<String> y1 = new X<>(1,1).new Y<>();\n" +
1211
			"		X<Integer>.Y<String> y2 = new X<>(1,1).new Y<>(1);\n" +
1212
			"		X<Integer>.Y<String> y3 = new X<>(1).new Y<>(1);\n" +
1213
			"		X<Integer>.Y<String> y4 = new X<>(1).new Y<>(\"\",\"\");\n" +
1214
			"		X<Integer>.Y<String> y5 = new X<>(1).new Y<>(1,\"\");\n" +
1215
			"		X<Integer>.Y<String> y6 = new X<>().new Y<>(1,\"\");\n" +
1216
			"		X<Integer>.Y<String> y7 = new X<>().new Y<>(1,1);\n" +
1217
			"	 }\n" +
1218
			"}\n"
1219
		},
1220
		"----------\n" + 
1221
		"1. ERROR in X.java (at line 3)\n" + 
1222
		"	X<String> f2 = new X<>(new Y()); \n" + 
1223
		"	                           ^\n" + 
1224
		"Y cannot be resolved to a type\n" + 
1225
		"----------\n");
1226
}
1227
// https://bugs.eclipse.org/bugs/show_bug.cgi?id=345559
1228
// TODO(ayush) enable and update the error message after bug 345968 is fixed
1229
public void _test0032() {
1230
	this.runNegativeTest(
1231
		new String[] {
1232
			"X.java",
1233
			"public class X<T>  {\n" +
1234
			"    X(T t) {}\n" +
1235
			"    X() {}\n" +
1236
			"    X(String abc, String abc2, T... t) {}\n" +
1237
			"    void foo(T a) {\n" +
1238
			"	 System.out.println(a);\n" +
1239
			"	 }\n" +
1240
			"	 class Y<K>{\n" +
1241
			"		Y(T t,String abc, K... k) {}\n" +
1242
			"	 }\n" +
1243
			"    public static void main(String[] args) {\n" +
1244
			"		X<Integer> x1 = new X<>(1,1);\n" +
1245
			"		X<Integer> x2 = new X<>(1);\n" +
1246
			"		X<Integer> x3 = new X<>();\n" +
1247
			"		X<Integer> x4 = new X<>(\"\",\"\");\n" +
1248
			"		X<Integer> x5 = new X<>(\"\",\"\",\"\");\n" +
1249
			"		X<Integer> x6 = new X<>(\"\",\"\",1);\n" +
1250
			"		X<Integer>.Y<String> y1 = new X<>(1,1).new Y<>();\n" +
1251
			"		X<Integer>.Y<String> y2 = new X<>(\"\",1).new Y<>(\"\");\n" +
1252
			"		X<Integer>.Y<String> y3 = new X<>(1).new Y<>(1);\n" +
1253
			"		X<Integer>.Y<String> y4 = new X<>(1).new Y<>(1,\"\");\n" +
1254
			"		X<Integer>.Y<String> y5 = new X<>(1).new Y<>(1,\"\",\"\");\n" +
1255
			"		X<Integer>.Y<String> y6 = new X<>().new Y<>(1,\"\",1);\n" +
1256
			"		X<Integer>.Y<String> y7 = new X<>().new Y<>(\"\",\"\",1);\n" +
1257
			"	 }\n" +
1258
			"}\n"
1259
		},
1260
		"----------\n" + 
1261
		"1. ERROR in X.java (at line 3)\n" + 
1262
		"	X<String> f2 = new X<>(new Y()); \n" + 
1263
		"	                           ^\n" + 
1264
		"Y cannot be resolved to a type\n" + 
1265
		"----------\n");
1266
}
1267
// https://bugs.eclipse.org/bugs/show_bug.cgi?id=345559
1268
// TODO(ayush) enable and update the error message after bug 345968 is fixed
1269
public void _test0033() {
1270
	this.runNegativeTest(
1271
		new String[] {
1272
			"X.java",
1273
			"public class X<T>  {\n" +
1274
			"    X(T t) {}\n" +
1275
			"    X() {}\n" +
1276
			"    X(String abc, String abc2, T... t) {}\n" +
1277
			"    void foo(T a) {\n" +
1278
			"	 System.out.println(a);\n" +
1279
			"	 }\n" +
1280
			"	 class Y<K>{\n" +
1281
			"		Y(T t,String abc, K... k) {}\n" +
1282
			"	 }\n" +
1283
			"	X<Integer> x1 = new X<>(1,1);\n" +
1284
			"	X<Integer> x2 = new X<>(1);\n" +
1285
			"	X<Integer> x3 = new X<>();\n" +
1286
			"	X<Integer> x4 = new X<>(\"\",\"\");\n" +
1287
			"	X<Integer> x5 = new X<>(\"\",\"\",\"\");\n" +
1288
			"	X<Integer> x6 = new X<>(\"\",\"\",1);\n" +
1289
			"	X<Integer>.Y<String> y1 = new X<>(1,1).new Y<>();\n" +
1290
			"	X<Integer>.Y<String> y2 = new X<>(\"\",1).new Y<>(\"\");\n" +
1291
			"	X<Integer>.Y<String> y3 = new X<>(1).new Y<>(1);\n" +
1292
			"	X<Integer>.Y<String> y4 = new X<>(1).new Y<>(1,\"\");\n" +
1293
			"	X<Integer>.Y<String> y5 = new X<>(1).new Y<>(1,\"\",\"\");\n" +
1294
			"	X<Integer>.Y<String> y6 = new X<>().new Y<>(1,\"\",1);\n" +
1295
			"	X<Integer>.Y<String> y7 = new X<>().new Y<>(\"\",\"\",1);\n" +
1296
			"}\n"
1297
		},
1298
		"----------\n" + 
1299
		"1. ERROR in X.java (at line 3)\n" + 
1300
		"	X<String> f2 = new X<>(new Y()); \n" + 
1301
		"	                           ^\n" + 
1302
		"Y cannot be resolved to a type\n" + 
1303
		"----------\n");
1304
}
1305
// https://bugs.eclipse.org/bugs/show_bug.cgi?id=345559
1306
public void test0034() {
1307
	this.runNegativeTest(
1308
		new String[] {
1309
			"X.java",
1310
			"public class X<T>  {\n" +
1311
			"    X(T t) {}\n" +
1312
			"    X() {}\n" +
1313
			"    void foo(T a) {\n" +
1314
			"	 System.out.println(a);\n" +
1315
			"	 }\n" +
1316
			"    public static void main(String[] args) {\n" +
1317
			"		X<Integer> x1 = new X<>(1,1);\n" +
1318
			"		X<Integer> x2 = new X<>(1);\n" +
1319
			"		X<Integer> x3 = new X<>();\n" +
1320
			"	 }\n" +
1321
			"}\n"
1322
		},
1323
		"----------\n" + 
1324
		"1. ERROR in X.java (at line 8)\n" + 
1325
		"	X<Integer> x1 = new X<>(1,1);\n" + 
1326
		"	                ^^^^^^^^^^^^\n" + 
1327
		"Cannot infer elided type(s)\n" + 
1328
		"----------\n");
1329
}
1330
// https://bugs.eclipse.org/bugs/show_bug.cgi?id=345559
1331
public void test0035() {
1332
	this.runNegativeTest(
1333
		new String[] {
1334
			"X.java",
1335
			"public class X<T>  {\n" +
1336
			"    X(T t) {}\n" +
1337
			"    X() {}\n" +
1338
			"	 @SafeVarargs\n" +
1339
			"    X(String abc, String abc2, T... t) {}\n" +
1340
			"    void foo(T a) {\n" +
1341
			"	 	System.out.println(a);\n" +
1342
			"	 }\n" +
1343
			"    public static void main(String[] args) {\n" +
1344
			"		X<Integer> x1 = new X<>(1,1);\n" +
1345
			"		X<Integer> x2 = new X<>(1);\n" +
1346
			"		X<Integer> x3 = new X<>();\n" +
1347
			"		X<Integer> x4 = new X<>(\"\",\"\");\n" +
1348
			"		X<Integer> x5 = new X<>(\"\",\"\",\"\");\n" +
1349
			"		X<Integer> x6 = new X<>(\"\",\"\",1);\n" +
1350
			"	 }\n" +
1351
			"}\n"
1352
		},
1353
		"----------\n" + 
1354
		"1. ERROR in X.java (at line 10)\n" + 
1355
		"	X<Integer> x1 = new X<>(1,1);\n" + 
1356
		"	                ^^^^^^^^^^^^\n" + 
1357
		"Cannot infer elided type(s)\n" + 
1358
		"----------\n" + 
1359
		"2. ERROR in X.java (at line 14)\n" + 
1360
		"	X<Integer> x5 = new X<>(\"\",\"\",\"\");\n" + 
1361
		"	                ^^^^^^^^^^^^^^^^^\n" + 
1362
		"Type mismatch: cannot convert from X<String> to X<Integer>\n" + 
1363
		"----------\n");
1364
}
1365
// https://bugs.eclipse.org/bugs/show_bug.cgi?id=345559
1366
public void test0036() {
1367
	this.runNegativeTest(
1368
		new String[] {
1369
			"X.java",
1370
			"public class X<T>  {\n" +
1371
			"    X(T t) {}\n" +
1372
			"    X() {}\n" +
1373
			"	 @SafeVarargs\n" +
1374
			"    X(String abc, String abc2, T... t) {}\n" +
1375
			"    void foo(T a) {\n" +
1376
			"	 System.out.println(a);\n" +
1377
			"	 }\n" +
1378
			"	X<Integer> x1 = new X<>(1,1);\n" +
1379
			"	X<Integer> x2 = new X<>(1);\n" +
1380
			"	X<Integer> x3 = new X<>();\n" +
1381
			"	X<Integer> x4 = new X<>(\"\",\"\");\n" +
1382
			"	X<Integer> x5 = new X<>(\"\",\"\",\"\");\n" +
1383
			"	X<Integer> x6 = new X<>(\"\",\"\",1);\n" +
1384
			"}\n"
1385
		},
1386
		"----------\n" + 
1387
		"1. ERROR in X.java (at line 9)\n" + 
1388
		"	X<Integer> x1 = new X<>(1,1);\n" + 
1389
		"	                ^^^^^^^^^^^^\n" + 
1390
		"Cannot infer elided type(s)\n" + 
1391
		"----------\n" + 
1392
		"2. ERROR in X.java (at line 13)\n" + 
1393
		"	X<Integer> x5 = new X<>(\"\",\"\",\"\");\n" + 
1394
		"	                ^^^^^^^^^^^^^^^^^\n" + 
1395
		"Type mismatch: cannot convert from X<String> to X<Integer>\n" + 
1396
		"----------\n");
1397
}
1398
// https://bugs.eclipse.org/bugs/show_bug.cgi?id=345559
1399
public void test0037() {
1400
	this.runNegativeTest(
1401
		new String[] {
1402
			"X.java",
1403
			"public class X<T>  {\n" +
1404
			"    X(T t) {}\n" +
1405
			"    X() {}\n" +
1406
			"	 @SafeVarargs\n" +
1407
			"    X(String abc, String abc2, T... t) {}\n" +
1408
			"    void foo(T a) {\n" +
1409
			"	 System.out.println(a);\n" +
1410
			"	 }\n" +
1411
			"	 class Y<K>{\n" +
1412
			"		@SafeVarargs\n" +
1413
			"		Y(T t,String abc, K... k) {}\n" +
1414
			"	 }\n" +
1415
			"    public static void main(String[] args) {\n" +
1416
			"		X<Integer>.Y<String> y1 = new X<>().new Y<>(1);\n" +
1417
			"		X<Integer>.Y<String> y2 = new X<>(1).new Y<>(1);\n" +
1418
			"		X<Integer>.Y<String> y3 = new X<>(\"\",\"\",1).new Y<>(1);\n" +
1419
			"		X<Integer>.Y<String> y4 = new X<>(1,\"\").new Y<>(1,\"\");\n" +
1420
			"	 }\n" +
1421
			"}\n"
1422
		},
1423
		"----------\n" + 
1424
		"1. ERROR in X.java (at line 14)\n" + 
1425
		"	X<Integer>.Y<String> y1 = new X<>().new Y<>(1);\n" + 
1426
		"	                          ^^^^^^^^^^^^^^^^^^^^\n" + 
1427
		"Cannot infer elided type(s)\n" + 
1428
		"----------\n" + 
1429
		"2. ERROR in X.java (at line 15)\n" + 
1430
		"	X<Integer>.Y<String> y2 = new X<>(1).new Y<>(1);\n" + 
1431
		"	                          ^^^^^^^^^^^^^^^^^^^^^\n" + 
1432
		"Cannot infer elided type(s)\n" + 
1433
		"----------\n" + 
1434
		"3. ERROR in X.java (at line 16)\n" + 
1435
		"	X<Integer>.Y<String> y3 = new X<>(\"\",\"\",1).new Y<>(1);\n" + 
1436
		"	                          ^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + 
1437
		"Cannot infer elided type(s)\n" + 
1438
		"----------\n" + 
1439
		"4. ERROR in X.java (at line 17)\n" + 
1440
		"	X<Integer>.Y<String> y4 = new X<>(1,\"\").new Y<>(1,\"\");\n" + 
1441
		"	                          ^^^^^^^^^^^^^\n" + 
1442
		"Cannot infer elided type(s)\n" + 
1443
		"----------\n");
1444
}
1201
public static Class testClass() {
1445
public static Class testClass() {
1202
	return GenericsRegressionTest_1_7.class;
1446
	return GenericsRegressionTest_1_7.class;
1203
}
1447
}

Return to bug 345559