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

Collapse All | Expand All

(-)compiler/org/eclipse/jdt/internal/compiler/lookup/Scope.java (-1 / +3 lines)
Lines 422-428 Link Here
422
			if (method instanceof ParameterizedGenericMethodBinding) {
422
			if (method instanceof ParameterizedGenericMethodBinding) {
423
				if (!((ParameterizedGenericMethodBinding) method).wasInferred) {
423
				if (!((ParameterizedGenericMethodBinding) method).wasInferred) {
424
					// attempt to invoke generic method of raw type with type hints <String>foo()
424
					// attempt to invoke generic method of raw type with type hints <String>foo()
425
					return new ProblemMethodBinding(method, method.selector, genericTypeArguments, ProblemReasons.TypeArgumentsForRawGenericMethod);
425
					if (compilerOptions().complianceLevel < ClassFileConstants.JDK1_7) {
426
						return new ProblemMethodBinding(method, method.selector, genericTypeArguments, ProblemReasons.TypeArgumentsForRawGenericMethod);
427
					}
426
				}
428
				}
427
			} else {
429
			} else {
428
				if (compilerOptions().complianceLevel < ClassFileConstants.JDK1_7) {
430
				if (compilerOptions().complianceLevel < ClassFileConstants.JDK1_7) {
(-)src/org/eclipse/jdt/core/tests/compiler/regression/GenericTypeTest.java (-113 / +277 lines)
Lines 7369-7405 Link Here
7369
	}
7369
	}
7370
	// generic method of raw type
7370
	// generic method of raw type
7371
	public void test0245() {
7371
	public void test0245() {
7372
		if (this.complianceLevel < ClassFileConstants.JDK1_7) {
7373
			this.runNegativeTest(
7374
					new String[] {
7375
						"X.java",
7376
						"public class X <T> { \n" + 
7377
						"        <G> T foo(G g) {\n" + 
7378
						"            return null;\n" + 
7379
						"        }\n" + 
7380
						"        T bar(T t) {\n" + 
7381
						"        	return zork;\n" + 
7382
						"        }\n" + 
7383
						"\n" + 
7384
						"        public static void main(String[] args) {\n" + 
7385
						"                X rx = new X();\n" + 
7386
						"                rx.<String>foo(\"hello\"); // Eclipse error here\n" + 
7387
						"                rx.<String>bar(\"hello\"); // Eclipse error here\n" + 
7388
						"        }\n" + 
7389
						"}\n"
7390
					},
7391
					"----------\n" + 
7392
					"1. ERROR in X.java (at line 6)\n" + 
7393
					"	return zork;\n" + 
7394
					"	       ^^^^\n" + 
7395
					"zork cannot be resolved\n" + 
7396
					"----------\n" + 
7397
					"2. WARNING in X.java (at line 10)\n" + 
7398
					"	X rx = new X();\n" + 
7399
					"	^\n" + 
7400
					"X is a raw type. References to generic type X<T> should be parameterized\n" + 
7401
					"----------\n" + 
7402
					"3. WARNING in X.java (at line 10)\n" + 
7403
					"	X rx = new X();\n" + 
7404
					"	           ^\n" + 
7405
					"X is a raw type. References to generic type X<T> should be parameterized\n" + 
7406
					"----------\n" + 
7407
					"4. ERROR in X.java (at line 11)\n" + 
7408
					"	rx.<String>foo(\"hello\"); // Eclipse error here\n" + 
7409
					"	           ^^^\n" + 
7410
					"The method foo(Object) of raw type X is no longer generic; it cannot be parameterized with arguments <String>\n" + 
7411
					"----------\n" + 
7412
					"5. ERROR in X.java (at line 12)\n" + 
7413
					"	rx.<String>bar(\"hello\"); // Eclipse error here\n" + 
7414
					"	           ^^^\n" + 
7415
					"The method bar(Object) of type X is not generic; it cannot be parameterized with arguments <String>\n" + 
7416
					"----------\n",
7417
					JavacTestOptions.EclipseHasABug.EclipseBug236242);
7418
			return;
7419
		}
7372
		this.runNegativeTest(
7420
		this.runNegativeTest(
7373
			new String[] {
7421
				new String[] {
7374
				"X.java",
7422
					"X.java",
7375
				"public class X <T> { \n" +
7423
					"public class X <T> { \n" + 
7376
				"	<G> T foo(G g) {\n" +
7424
					"        <G> T foo(G g) {\n" + 
7377
				"		return null;\n" +
7425
					"            return null;\n" + 
7378
				"	}\n" +
7426
					"        }\n" + 
7379
				"	\n" +
7427
					"        T bar(T t) {\n" + 
7380
				"	public static void main(String[] args) {\n" +
7428
					"        	return zork;\n" + 
7381
				"		X rx = new X();\n" +
7429
					"        }\n" + 
7382
				"		rx.<String>foo(\"hello\");\n" +
7430
					"\n" + 
7383
				"	}\n" +
7431
					"        public static void main(String[] args) {\n" + 
7384
				"}\n"
7432
					"                X rx = new X();\n" + 
7385
			},
7433
					"                rx.<String>foo(\"hello\"); // Eclipse error here\n" + 
7386
			"----------\n" +
7434
					"                rx.<String>bar(\"hello\"); // Eclipse error here\n" + 
7387
			"1. WARNING in X.java (at line 7)\n" +
7435
					"        }\n" + 
7388
			"	X rx = new X();\n" +
7436
					"}\n"
7389
			"	^\n" +
7437
				},
7390
			"X is a raw type. References to generic type X<T> should be parameterized\n" +
7438
				"----------\n" + 
7391
			"----------\n" +
7439
				"1. ERROR in X.java (at line 6)\n" + 
7392
			"2. WARNING in X.java (at line 7)\n" +
7440
				"	return zork;\n" + 
7393
			"	X rx = new X();\n" +
7441
				"	       ^^^^\n" + 
7394
			"	           ^\n" +
7442
				"zork cannot be resolved\n" + 
7395
			"X is a raw type. References to generic type X<T> should be parameterized\n" +
7443
				"----------\n" + 
7396
			"----------\n" +
7444
				"2. WARNING in X.java (at line 10)\n" + 
7397
			"3. ERROR in X.java (at line 8)\n" +
7445
				"	X rx = new X();\n" + 
7398
			"	rx.<String>foo(\"hello\");\n" +
7446
				"	^\n" + 
7399
			"	           ^^^\n" +
7447
				"X is a raw type. References to generic type X<T> should be parameterized\n" + 
7400
			"The method foo(Object) of raw type X is no longer generic; it cannot be parameterized with arguments <String>\n" +
7448
				"----------\n" + 
7401
			"----------\n",
7449
				"3. WARNING in X.java (at line 10)\n" + 
7402
			JavacTestOptions.EclipseHasABug.EclipseBug236242);
7450
				"	X rx = new X();\n" + 
7451
				"	           ^\n" + 
7452
				"X is a raw type. References to generic type X<T> should be parameterized\n" + 
7453
				"----------\n" + 
7454
				"4. WARNING in X.java (at line 11)\n" + 
7455
				"	rx.<String>foo(\"hello\"); // Eclipse error here\n" + 
7456
				"	^^^^^^^^^^^^^^^^^^^^^^^\n" + 
7457
				"Type safety: The method foo(Object) belongs to the raw type X. References to generic type X<T> should be parameterized\n" + 
7458
				"----------\n" + 
7459
				"5. WARNING in X.java (at line 12)\n" + 
7460
				"	rx.<String>bar(\"hello\"); // Eclipse error here\n" + 
7461
				"	^^^^^^^^^^^^^^^^^^^^^^^\n" + 
7462
				"Type safety: The method bar(Object) belongs to the raw type X. References to generic type X<T> should be parameterized\n" + 
7463
				"----------\n" + 
7464
				"6. WARNING in X.java (at line 12)\n" + 
7465
				"	rx.<String>bar(\"hello\"); // Eclipse error here\n" + 
7466
				"	    ^^^^^^\n" + 
7467
				"Unused type arguments for the non generic method bar(Object) of type X; it should not be parameterized with arguments <String>\n" + 
7468
				"----------\n",
7469
				JavacTestOptions.EclipseHasABug.EclipseBug236242);
7403
	}
7470
	}
7404
	// https://bugs.eclipse.org/bugs/show_bug.cgi?id=69320 parameterized type compatibility
7471
	// https://bugs.eclipse.org/bugs/show_bug.cgi?id=69320 parameterized type compatibility
7405
	public void test0246() {
7472
	public void test0246() {
Lines 10156-10207 Link Here
10156
	}
10223
	}
10157
	// checking scenario where generic type and method share the same type parameter name
10224
	// checking scenario where generic type and method share the same type parameter name
10158
	public void test0344() {
10225
	public void test0344() {
10226
		if (this.complianceLevel < ClassFileConstants.JDK1_7) {
10227
			this.runNegativeTest(
10228
				new String[] {
10229
					"X.java",
10230
					"import java.io.IOException;\n" +
10231
					"\n" +
10232
					"public abstract class X<T extends Runnable> {\n" +
10233
					"	\n" +
10234
					"	public abstract <T extends Exception> T bar(T t);\n" +
10235
					"\n" +
10236
					"	static void foo(X x) {\n" +
10237
					"		x.<Exception>bar(null);\n" +
10238
					"		\n" +
10239
					"		class R implements Runnable {\n" +
10240
					"			public void run() {\n" +
10241
					"			}\n" +
10242
					"		}\n" +
10243
					"		X<R> xr = new X<R>(){  \n" +
10244
					"			public <T> T bar(T t) { \n" +
10245
					"				return t; \n" +
10246
					"			}\n" +
10247
					"		};\n" +
10248
					"		IOException e = xr.bar(new IOException());\n" +
10249
					"	}\n" +
10250
					"}\n"
10251
				},
10252
				"----------\n" + 
10253
				"1. WARNING in X.java (at line 5)\n" + 
10254
				"	public abstract <T extends Exception> T bar(T t);\n" + 
10255
				"	                 ^\n" + 
10256
				"The type parameter T is hiding the type T\n" + 
10257
				"----------\n" + 
10258
				"2. WARNING in X.java (at line 7)\n" + 
10259
				"	static void foo(X x) {\n" + 
10260
				"	                ^\n" + 
10261
				"X is a raw type. References to generic type X<T> should be parameterized\n" + 
10262
				"----------\n" + 
10263
				"3. ERROR in X.java (at line 8)\n" + 
10264
				"	x.<Exception>bar(null);\n" + 
10265
				"	             ^^^\n" + 
10266
				"The method bar(Exception) of raw type X is no longer generic; it cannot be parameterized with arguments <Exception>\n" + 
10267
				"----------\n" + 
10268
				"4. ERROR in X.java (at line 14)\n" + 
10269
				"	X<R> xr = new X<R>(){  \n" + 
10270
				"	              ^^^^^^\n" + 
10271
				"The type new X<R>(){} must implement the inherited abstract method X<R>.bar(T)\n" + 
10272
				"----------\n");
10273
			return;
10274
		}
10159
		this.runNegativeTest(
10275
		this.runNegativeTest(
10160
			new String[] {
10276
				new String[] {
10161
				"X.java",
10277
					"X.java",
10162
				"import java.io.IOException;\n" +
10278
					"import java.io.IOException;\n" +
10163
				"\n" +
10279
					"\n" +
10164
				"public abstract class X<T extends Runnable> {\n" +
10280
					"public abstract class X<T extends Runnable> {\n" +
10165
				"	\n" +
10281
					"	\n" +
10166
				"	public abstract <T extends Exception> T bar(T t);\n" +
10282
					"	public abstract <T extends Exception> T bar(T t);\n" +
10167
				"\n" +
10283
					"\n" +
10168
				"	static void foo(X x) {\n" +
10284
					"	static void foo(X x) {\n" +
10169
				"		x.<Exception>bar(null);\n" +
10285
					"		x.<Exception>bar(null);\n" +
10170
				"		\n" +
10286
					"		\n" +
10171
				"		class R implements Runnable {\n" +
10287
					"		class R implements Runnable {\n" +
10172
				"			public void run() {\n" +
10288
					"			public void run() {\n" +
10173
				"			}\n" +
10289
					"			}\n" +
10174
				"		}\n" +
10290
					"		}\n" +
10175
				"		X<R> xr = new X<R>(){  \n" +
10291
					"		X<R> xr = new X<R>(){  \n" +
10176
				"			public <T> T bar(T t) { \n" +
10292
					"			public <T> T bar(T t) { \n" +
10177
				"				return t; \n" +
10293
					"				return t; \n" +
10178
				"			}\n" +
10294
					"			}\n" +
10179
				"		};\n" +
10295
					"		};\n" +
10180
				"		IOException e = xr.bar(new IOException());\n" +
10296
					"		IOException e = xr.bar(new IOException());\n" +
10181
				"	}\n" +
10297
					"	}\n" +
10182
				"}\n"
10298
					"}\n"
10183
			},
10299
				},
10184
			"----------\n" +
10300
				"----------\n" + 
10185
			"1. WARNING in X.java (at line 5)\n" +
10301
				"1. WARNING in X.java (at line 5)\n" + 
10186
			"	public abstract <T extends Exception> T bar(T t);\n" +
10302
				"	public abstract <T extends Exception> T bar(T t);\n" + 
10187
			"	                 ^\n" +
10303
				"	                 ^\n" + 
10188
			"The type parameter T is hiding the type T\n" +
10304
				"The type parameter T is hiding the type T\n" + 
10189
			"----------\n" +
10305
				"----------\n" + 
10190
			"2. WARNING in X.java (at line 7)\n" +
10306
				"2. WARNING in X.java (at line 7)\n" + 
10191
			"	static void foo(X x) {\n" +
10307
				"	static void foo(X x) {\n" + 
10192
			"	                ^\n" +
10308
				"	                ^\n" + 
10193
			"X is a raw type. References to generic type X<T> should be parameterized\n" +
10309
				"X is a raw type. References to generic type X<T> should be parameterized\n" + 
10194
			"----------\n" +
10310
				"----------\n" + 
10195
			"3. ERROR in X.java (at line 8)\n" +
10311
				"3. WARNING in X.java (at line 8)\n" + 
10196
			"	x.<Exception>bar(null);\n" +
10312
				"	x.<Exception>bar(null);\n" + 
10197
			"	             ^^^\n" +
10313
				"	^^^^^^^^^^^^^^^^^^^^^^\n" + 
10198
			"The method bar(Exception) of raw type X is no longer generic; it cannot be parameterized with arguments <Exception>\n" +
10314
				"Type safety: The method bar(Exception) belongs to the raw type X. References to generic type X<T> should be parameterized\n" + 
10199
			"----------\n" +
10315
				"----------\n" + 
10200
			"4. ERROR in X.java (at line 14)\n" +
10316
				"4. ERROR in X.java (at line 14)\n" + 
10201
			"	X<R> xr = new X<R>(){  \n" +
10317
				"	X<R> xr = new X<R>(){  \n" + 
10202
			"	              ^^^^^^\n" +
10318
				"	              ^^^^^^\n" + 
10203
			"The type new X<R>(){} must implement the inherited abstract method X<R>.bar(T)\n" +
10319
				"The type new X<R>(){} must implement the inherited abstract method X<R>.bar(T)\n" + 
10204
			"----------\n");
10320
				"----------\n");		
10205
	}
10321
	}
10206
	// https://bugs.eclipse.org/bugs/show_bug.cgi?id=74594
10322
	// https://bugs.eclipse.org/bugs/show_bug.cgi?id=74594
10207
	public void test0345() {
10323
	public void test0345() {
Lines 10306-10351 Link Here
10306
	}
10422
	}
10307
	// checking scenario where generic type and method share the same type parameter name
10423
	// checking scenario where generic type and method share the same type parameter name
10308
	public void test0348() {
10424
	public void test0348() {
10309
		this.runNegativeTest(
10425
		if (this.complianceLevel < ClassFileConstants.JDK1_7) {
10310
			new String[] {
10426
			this.runNegativeTest(
10311
				"X.java",
10427
				new String[] {
10312
				"import java.io.IOException;\n" +
10428
					"X.java",
10313
				"public abstract class X<T extends Runnable> {\n" +
10429
					"import java.io.IOException;\n" +
10430
					"public abstract class X<T extends Runnable> {\n" +
10431
					"	public abstract <T extends Exception> T bar(T t);\n" +
10432
					"	static void foo(X x) {\n" +
10433
					"		x.<Exception>bar(null);\n" +
10434
					"		class R implements Runnable {\n" +
10435
					"			public void run() {}\n" +
10436
					"		}\n" +
10437
					"		X<R> xr = new X<R>(){  \n" +
10438
					"			public <T extends Exception> T bar(T t) { return t; }\n" +
10439
					"		};\n" +
10440
					"		IOException e = xr.bar(new IOException());\n" +
10441
					"	}\n" +
10442
					"}\n"
10443
				},
10444
				"----------\n" +
10445
				"1. WARNING in X.java (at line 3)\n" +
10314
				"	public abstract <T extends Exception> T bar(T t);\n" +
10446
				"	public abstract <T extends Exception> T bar(T t);\n" +
10447
				"	                 ^\n" +
10448
				"The type parameter T is hiding the type T\n" +
10449
				"----------\n" +
10450
				"2. WARNING in X.java (at line 4)\n" +
10315
				"	static void foo(X x) {\n" +
10451
				"	static void foo(X x) {\n" +
10316
				"		x.<Exception>bar(null);\n" +
10452
				"	                ^\n" +
10317
				"		class R implements Runnable {\n" +
10453
				"X is a raw type. References to generic type X<T> should be parameterized\n" +
10318
				"			public void run() {}\n" +
10454
				"----------\n" +
10319
				"		}\n" +
10455
				"3. ERROR in X.java (at line 5)\n" +
10320
				"		X<R> xr = new X<R>(){  \n" +
10456
				"	x.<Exception>bar(null);\n" +
10321
				"			public <T extends Exception> T bar(T t) { return t; }\n" +
10457
				"	             ^^^\n" +
10322
				"		};\n" +
10458
				"The method bar(Exception) of raw type X is no longer generic; it cannot be parameterized with arguments <Exception>\n" +
10323
				"		IOException e = xr.bar(new IOException());\n" +
10459
				"----------\n" +
10324
				"	}\n" +
10460
				"4. WARNING in X.java (at line 10)\n" +
10325
				"}\n"
10461
				"	public <T extends Exception> T bar(T t) { return t; }\n" +
10326
			},
10462
				"	                               ^^^^^^^^\n" +
10327
			"----------\n" +
10463
				"The method bar(T) of type new X<R>(){} should be tagged with @Override since it actually overrides a superclass method\n" +
10328
			"1. WARNING in X.java (at line 3)\n" +
10464
				"----------\n",
10329
			"	public abstract <T extends Exception> T bar(T t);\n" +
10465
				JavacTestOptions.EclipseHasABug.EclipseBug236242);
10330
			"	                 ^\n" +
10466
			return;
10331
			"The type parameter T is hiding the type T\n" +
10467
		}
10332
			"----------\n" +
10468
		this.runNegativeTest(
10333
			"2. WARNING in X.java (at line 4)\n" +
10469
				new String[] {
10334
			"	static void foo(X x) {\n" +
10470
					"X.java",
10335
			"	                ^\n" +
10471
					"import java.io.IOException;\n" +
10336
			"X is a raw type. References to generic type X<T> should be parameterized\n" +
10472
					"public abstract class X<T extends Runnable> {\n" +
10337
			"----------\n" +
10473
					"	public abstract <T extends Exception> T bar(T t);\n" +
10338
			"3. ERROR in X.java (at line 5)\n" +
10474
					"	static void foo(X x) {\n" +
10339
			"	x.<Exception>bar(null);\n" +
10475
					"		x.<Exception>bar(null);\n" +
10340
			"	             ^^^\n" +
10476
					"		class R implements Runnable {\n" +
10341
			"The method bar(Exception) of raw type X is no longer generic; it cannot be parameterized with arguments <Exception>\n" +
10477
					"			public void run() { zork = 0; }\n" +
10342
			"----------\n" +
10478
					"		}\n" +
10343
			"4. WARNING in X.java (at line 10)\n" +
10479
					"		X<R> xr = new X<R>(){  \n" +
10344
			"	public <T extends Exception> T bar(T t) { return t; }\n" +
10480
					"			public <T extends Exception> T bar(T t) { return t; }\n" +
10345
			"	                               ^^^^^^^^\n" +
10481
					"		};\n" +
10346
			"The method bar(T) of type new X<R>(){} should be tagged with @Override since it actually overrides a superclass method\n" +
10482
					"		IOException e = xr.bar(new IOException());\n" +
10347
			"----------\n",
10483
					"	}\n" +
10348
			JavacTestOptions.EclipseHasABug.EclipseBug236242);
10484
					"}\n"
10485
				},
10486
				"----------\n" + 
10487
				"1. WARNING in X.java (at line 3)\n" + 
10488
				"	public abstract <T extends Exception> T bar(T t);\n" + 
10489
				"	                 ^\n" + 
10490
				"The type parameter T is hiding the type T\n" + 
10491
				"----------\n" + 
10492
				"2. WARNING in X.java (at line 4)\n" + 
10493
				"	static void foo(X x) {\n" + 
10494
				"	                ^\n" + 
10495
				"X is a raw type. References to generic type X<T> should be parameterized\n" + 
10496
				"----------\n" + 
10497
				"3. WARNING in X.java (at line 5)\n" + 
10498
				"	x.<Exception>bar(null);\n" + 
10499
				"	^^^^^^^^^^^^^^^^^^^^^^\n" + 
10500
				"Type safety: The method bar(Exception) belongs to the raw type X. References to generic type X<T> should be parameterized\n" + 
10501
				"----------\n" + 
10502
				"4. ERROR in X.java (at line 7)\n" + 
10503
				"	public void run() { zork = 0; }\n" + 
10504
				"	                    ^^^^\n" + 
10505
				"zork cannot be resolved\n" + 
10506
				"----------\n" + 
10507
				"5. WARNING in X.java (at line 10)\n" + 
10508
				"	public <T extends Exception> T bar(T t) { return t; }\n" + 
10509
				"	                               ^^^^^^^^\n" + 
10510
				"The method bar(T) of type new X<R>(){} should be tagged with @Override since it actually overrides a superclass method\n" + 
10511
				"----------\n",
10512
				JavacTestOptions.EclipseHasABug.EclipseBug236242);		
10349
	}
10513
	}
10350
	// test wildcard compatibilities
10514
	// test wildcard compatibilities
10351
	public void test0349() {
10515
	public void test0349() {

Return to bug 236242