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 242159 | Differences between
and this patch

Collapse All | Expand All

(-)compiler/org/eclipse/jdt/internal/compiler/lookup/InferenceContext.java (-3 / +27 lines)
Lines 1-10 Link Here
1
/*******************************************************************************
1
/*******************************************************************************
2
 * Copyright (c) 2000, 2009 IBM Corporation and others.
2
 * Copyright (c) 2000, 2011 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *
7
 *
8
 * This is an implementation of an early-draft specification developed under the Java
9
 * Community Process (JCP) and is made available for testing and evaluation purposes
10
 * only. The code is not compatible with any specification of the JCP.
11
 *
8
 * Contributors:
12
 * Contributors:
9
 *     IBM Corporation - initial API and implementation
13
 *     IBM Corporation - initial API and implementation
10
 *******************************************************************************/
14
 *******************************************************************************/
Lines 13-19 Link Here
13
/**
17
/**
14
 * Context used during type inference for a generic method invocation
18
 * Context used during type inference for a generic method invocation
15
 */
19
 */
16
public class InferenceContext {
20
public class InferenceContext implements Substitution {
17
21
18
	private TypeBinding[][][] collectedSubstitutes;
22
	private TypeBinding[][][] collectedSubstitutes;
19
	MethodBinding genericMethod;
23
	MethodBinding genericMethod;
Lines 23-36 Link Here
23
	boolean hasExplicitExpectedType; // indicates whether the expectedType (if set) was explicit in code, or set by default
27
	boolean hasExplicitExpectedType; // indicates whether the expectedType (if set) was explicit in code, or set by default
24
    public boolean isUnchecked;
28
    public boolean isUnchecked;
25
	TypeBinding[] substitutes;
29
	TypeBinding[] substitutes;
30
	private final LookupEnvironment environment;
26
	final static int FAILED = 1;
31
	final static int FAILED = 1;
27
32
28
public InferenceContext(MethodBinding genericMethod) {
33
public InferenceContext(MethodBinding genericMethod, LookupEnvironment environment) {
29
	this.genericMethod = genericMethod;
34
	this.genericMethod = genericMethod;
30
	TypeVariableBinding[] typeVariables = genericMethod.typeVariables;
35
	TypeVariableBinding[] typeVariables = genericMethod.typeVariables;
31
	int varLength = typeVariables.length;
36
	int varLength = typeVariables.length;
32
	this.collectedSubstitutes = new TypeBinding[varLength][3][];
37
	this.collectedSubstitutes = new TypeBinding[varLength][3][];
33
	this.substitutes = new TypeBinding[varLength];
38
	this.substitutes = new TypeBinding[varLength];
39
	this.environment = environment;
34
}
40
}
35
41
36
public TypeBinding[] getSubstitutes(TypeVariableBinding typeVariable, int constraint) {
42
public TypeBinding[] getSubstitutes(TypeVariableBinding typeVariable, int constraint) {
Lines 135-138 Link Here
135
	buffer.append(']');
141
	buffer.append(']');
136
	return buffer.toString();
142
	return buffer.toString();
137
}
143
}
144
145
public TypeBinding substitute(TypeVariableBinding originalVariable) {
146
    TypeVariableBinding[] variables = this.genericMethod.typeVariables;
147
    int length = variables.length;
148
    // check this variable can be substituted given parameterized type
149
    if (originalVariable.rank < length && variables[originalVariable.rank] == originalVariable) {
150
		return this.substitutes[originalVariable.rank];
151
    }
152
    return originalVariable;
153
}
154
155
public LookupEnvironment environment() {
156
	return this.environment;
157
}
158
159
public boolean isRawSubstitution() {
160
	return false;
161
}
138
}
162
}
(-)compiler/org/eclipse/jdt/internal/compiler/lookup/ParameterizedGenericMethodBinding.java (-11 / +38 lines)
Lines 5-15 Link Here
5
 * which accompanies this distribution, and is available at
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *
7
 *
8
 * This is an implementation of an early-draft specification developed under the Java
9
 * Community Process (JCP) and is made available for testing and evaluation purposes
10
 * only. The code is not compatible with any specification of the JCP.
11
 * 
8
 * Contributors:
12
 * Contributors:
9
 *     IBM Corporation - initial API and implementation
13
 *     IBM Corporation - initial API and implementation
10
 *******************************************************************************/
14
 *******************************************************************************/
11
package org.eclipse.jdt.internal.compiler.lookup;
15
package org.eclipse.jdt.internal.compiler.lookup;
12
16
17
import org.eclipse.jdt.internal.compiler.ast.Wildcard;
18
13
/**
19
/**
14
 * Binding denoting a generic method after type parameter substitutions got performed.
20
 * Binding denoting a generic method after type parameter substitutions got performed.
15
 * On parameterized type bindings, all methods got substituted, regardless whether
21
 * On parameterized type bindings, all methods got substituted, regardless whether
Lines 32-37 Link Here
32
		ParameterizedGenericMethodBinding methodSubstitute;
38
		ParameterizedGenericMethodBinding methodSubstitute;
33
		TypeVariableBinding[] typeVariables = originalMethod.typeVariables;
39
		TypeVariableBinding[] typeVariables = originalMethod.typeVariables;
34
		TypeBinding[] substitutes = invocationSite.genericTypeArguments();
40
		TypeBinding[] substitutes = invocationSite.genericTypeArguments();
41
		InferenceContext inferenceContext = null;
35
		TypeBinding[] uncheckedArguments = null;
42
		TypeBinding[] uncheckedArguments = null;
36
		computeSubstitutes: {
43
		computeSubstitutes: {
37
			if (substitutes != null) {
44
			if (substitutes != null) {
Lines 46-52 Link Here
46
			// perform type argument inference (15.12.2.7)
53
			// perform type argument inference (15.12.2.7)
47
			// initializes the map of substitutes (var --> type[][]{ equal, extends, super}
54
			// initializes the map of substitutes (var --> type[][]{ equal, extends, super}
48
			TypeBinding[] parameters = originalMethod.parameters;
55
			TypeBinding[] parameters = originalMethod.parameters;
49
			InferenceContext inferenceContext = new InferenceContext(originalMethod);
56
			inferenceContext = new InferenceContext(originalMethod, scope.environment());
50
			methodSubstitute = inferFromArgumentTypes(scope, originalMethod, arguments, parameters, inferenceContext);
57
			methodSubstitute = inferFromArgumentTypes(scope, originalMethod, arguments, parameters, inferenceContext);
51
			if (methodSubstitute == null)
58
			if (methodSubstitute == null)
52
				return null;
59
				return null;
Lines 74-85 Link Here
74
			}
81
			}
75
		}
82
		}
76
83
77
		// bounds check
84
		/* bounds check: https://bugs.eclipse.org/bugs/show_bug.cgi?id=242159, Inferred types may contain self reference
85
		   in formal bounds. If "T extends I<T>" is a original type variable and T was inferred to be I<T> due possibly
86
		   to under constraints and resultant glb application per 15.12.2.8, using this.typeArguments to drive the bounds
87
		   check against itself is doomed to fail. For, the variable T would after substitution be I<I<T>> and would fail
88
		   bounds check against I<T>. Use the inferred types from the context directly - see that there is one round of
89
		   extra substitution that has taken place to properly substitute a remaining unresolved variable which also appears
90
		   in a formal bound  (So we really have a bounds mismatch between I<I<T>> and I<I<I<T>>>, in the absence of a fix.)
91
		*/
78
		for (int i = 0, length = typeVariables.length; i < length; i++) {
92
		for (int i = 0, length = typeVariables.length; i < length; i++) {
79
		    TypeVariableBinding typeVariable = typeVariables[i];
93
		    TypeVariableBinding typeVariable = typeVariables[i];
80
		    TypeBinding substitute = methodSubstitute.typeArguments[i];
94
		    TypeBinding substitute = methodSubstitute.typeArguments[i];
81
		    if (uncheckedArguments != null && uncheckedArguments[i] == null) continue; // only bound check if inferred through 15.12.2.6
95
		    if (uncheckedArguments != null && uncheckedArguments[i] == null) continue; // only bound check if inferred through 15.12.2.6
82
			switch (typeVariable.boundCheck(methodSubstitute, substitute)) {
96
			switch (typeVariable.boundCheck((inferenceContext != null) ? inferenceContext : (Substitution) methodSubstitute, substitute)) {
83
				case TypeConstants.MISMATCH :
97
				case TypeConstants.MISMATCH :
84
			        // incompatible due to bound check
98
			        // incompatible due to bound check
85
					int argLength = arguments.length;
99
					int argLength = arguments.length;
Lines 233-244 Link Here
233
					if (bounds == null) continue nextTypeParameter;
247
					if (bounds == null) continue nextTypeParameter;
234
					TypeBinding[] glb = Scope.greaterLowerBound(bounds);
248
					TypeBinding[] glb = Scope.greaterLowerBound(bounds);
235
					TypeBinding mostSpecificSubstitute = null;
249
					TypeBinding mostSpecificSubstitute = null;
236
					if (glb != null) mostSpecificSubstitute = glb[0]; // TODO (philippe) need to improve
250
					// https://bugs.eclipse.org/bugs/show_bug.cgi?id=341795 - Per 15.12.2.8, we should fully apply glb
237
						//TypeBinding mostSpecificSubstitute = scope.greaterLowerBound(bounds);
251
					if (glb != null) {
238
						if (mostSpecificSubstitute != null) {
252
						if (glb.length == 1) {
239
							substitutes[i] = mostSpecificSubstitute;
253
							mostSpecificSubstitute = glb[0];
254
						} else {
255
							TypeBinding [] otherBounds = new TypeBinding[glb.length - 1];
256
							System.arraycopy(glb, 1, otherBounds, 0, glb.length - 1);
257
							mostSpecificSubstitute = scope.environment().createWildcard(null, 0, glb[0], otherBounds, Wildcard.EXTENDS);
240
						}
258
						}
241
					}
259
					}
260
					if (mostSpecificSubstitute != null) {
261
						substitutes[i] = mostSpecificSubstitute;
262
					}
263
				}
242
		}
264
		}
243
		return true;
265
		return true;
244
	}
266
	}
Lines 413-426 Link Here
413
    	for (int i = 0; i < varLength; i++) {
435
    	for (int i = 0; i < varLength; i++) {
414
    		TypeBinding substitute = inferenceContext.substitutes[i];
436
    		TypeBinding substitute = inferenceContext.substitutes[i];
415
    		if (substitute != null) {
437
    		if (substitute != null) {
416
    			this.typeArguments[i] = inferenceContext.substitutes[i];
438
    			this.typeArguments[i] = substitute;
417
    		} else {
439
    		} else {
418
    			// remaining unresolved variable are considered to be Object (or their bound actually)
440
    			// remaining unresolved variable are considered to be Object (or their bound actually)
419
	    		this.typeArguments[i] = originalVariables[i].upperBound();
441
	    		this.typeArguments[i] = inferenceContext.substitutes[i] = originalVariables[i].upperBound();
420
	    	}
442
	    	}
421
    	}
443
    	}
422
		// may still need an extra substitution at the end (see https://bugs.eclipse.org/bugs/show_bug.cgi?id=121369)
444
		/* May still need an extra substitution at the end (see https://bugs.eclipse.org/bugs/show_bug.cgi?id=121369)
423
		// to properly substitute a remaining unresolved variable which also appear in a formal bound
445
		   to properly substitute a remaining unresolved variable which also appear in a formal bound. See also
446
		   http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=5021635. It is questionable though whether this extra
447
		   substitution should take place when the invocation site offers no guidance whatsoever and the type variables
448
		   are inferred to be the glb of the published bounds - as there can recursion in the formal bounds, the
449
		   inferred bounds would no longer be glb. See also http://bugs.sun.com/view_bug.do?bug_id=6932571
450
		*/    	
424
    	this.typeArguments = Scope.substitute(this, this.typeArguments);
451
    	this.typeArguments = Scope.substitute(this, this.typeArguments);
425
452
426
    	// adjust method types to reflect latest inference
453
    	// adjust method types to reflect latest inference
(-)src/org/eclipse/jdt/core/tests/compiler/regression/GenericTypeTest.java (-103 / +57 lines)
Lines 5-10 Link Here
5
 * which accompanies this distribution, and is available at
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *
7
 *
8
 * This is an implementation of an early-draft specification developed under the Java
9
 * Community Process (JCP) and is made available for testing and evaluation purposes
10
 * only. The code is not compatible with any specification of the JCP.
11
 * 
8
 * Contributors:
12
 * Contributors:
9
 *     IBM Corporation - initial API and implementation
13
 *     IBM Corporation - initial API and implementation
10
 *******************************************************************************/
14
 *******************************************************************************/
Lines 31-37 Link Here
31
	// Static initializer to specify tests subset using TESTS_* static variables
35
	// Static initializer to specify tests subset using TESTS_* static variables
32
	// All specified tests which does not belong to the class are skipped...
36
	// All specified tests which does not belong to the class are skipped...
33
	static {
37
	static {
34
//		TESTS_NAMES = new String[] { "test1203c", "test1203d" };
38
//		TESTS_NAMES = new String[] { "test1404" };
35
//		TESTS_NUMBERS = new int[] { 593, 701, 746, 848, 953, 985, 1029, 1136, 1227, 1295, 1341 };
39
//		TESTS_NUMBERS = new int[] { 593, 701, 746, 848, 953, 985, 1029, 1136, 1227, 1295, 1341 };
36
//		TESTS_RANGE = new int[] { 1097, -1 };
40
//		TESTS_RANGE = new int[] { 1097, -1 };
37
	}
41
	}
Lines 12734-12740 Link Here
12734
	}
12738
	}
12735
12739
12736
	public void test0423() {
12740
	public void test0423() {
12737
		this.runNegativeTest(
12741
		this.runConformTest(
12738
			new String[] {
12742
			new String[] {
12739
				"X.java",
12743
				"X.java",
12740
				"public class X {\n" +
12744
				"public class X {\n" +
Lines 12753-12764 Link Here
12753
				"\n" +
12757
				"\n" +
12754
				"}",
12758
				"}",
12755
			},
12759
			},
12756
			"----------\n" +
12760
			"");
12757
			"1. ERROR in X.java (at line 12)\n" +
12758
			"	foo();\n" +
12759
			"	^^^\n" +
12760
			"Bound mismatch: The generic method foo() of type X is not applicable for the arguments (). The inferred type X is not a valid substitute for the bounded parameter <U extends X & Runnable>\n" +
12761
			"----------\n");
12762
	}
12761
	}
12763
12762
12764
	public void test0424() {
12763
	public void test0424() {
Lines 28389-28399 Link Here
28389
		"	String s = (String) Foo.foo();\n" +
28388
		"	String s = (String) Foo.foo();\n" +
28390
		"	           ^^^^^^^^^^^^^^^^^^\n" +
28389
		"	           ^^^^^^^^^^^^^^^^^^\n" +
28391
		"Cannot cast from List<List<U>> to String\n" +
28390
		"Cannot cast from List<List<U>> to String\n" +
28392
		"----------\n" +
28393
		"2. ERROR in X.java (at line 9)\n" +
28394
		"	String s = (String) Foo.foo();\n" +
28395
		"	                        ^^^\n" +
28396
		"Bound mismatch: The generic method foo() of type Foo is not applicable for the arguments (). The inferred type List<List<U>> is not a valid substitute for the bounded parameter <U extends List<U>>\n" +
28397
		"----------\n");
28391
		"----------\n");
28398
}
28392
}
28399
//https://bugs.eclipse.org/bugs/show_bug.cgi?id=121369 - variation
28393
//https://bugs.eclipse.org/bugs/show_bug.cgi?id=121369 - variation
Lines 31424-31440 Link Here
31424
		"	^\n" + 
31418
		"	^\n" + 
31425
		"X is a raw type. References to generic type X<A> should be parameterized\n" + 
31419
		"X is a raw type. References to generic type X<A> should be parameterized\n" + 
31426
		"----------\n" + 
31420
		"----------\n" + 
31427
		"2. ERROR in X.java (at line 7)\n" + 
31421
		"2. WARNING in X.java (at line 8)\n" + 
31428
		"	X x = newInstance();\n" + 
31429
		"	      ^^^^^^^^^^^\n" + 
31430
		"Bound mismatch: The generic method newInstance() of type X<A> is not applicable for the arguments (). The inferred type Comparable<Comparable<B>> is not a valid substitute for the bounded parameter <B extends Comparable<B>>\n" + 
31431
		"----------\n" + 
31432
		"3. WARNING in X.java (at line 8)\n" + 
31433
		"	return new X[] { x };\n" + 
31422
		"	return new X[] { x };\n" + 
31434
		"	       ^^^^^^^^^^^^^\n" + 
31423
		"	       ^^^^^^^^^^^^^\n" + 
31435
		"Type safety: The expression of type X[] needs unchecked conversion to conform to X<String>[]\n" + 
31424
		"Type safety: The expression of type X[] needs unchecked conversion to conform to X<String>[]\n" + 
31436
		"----------\n" + 
31425
		"----------\n" + 
31437
		"4. ERROR in X.java (at line 10)\n" + 
31426
		"3. ERROR in X.java (at line 10)\n" + 
31438
		"	Zork z;\n" + 
31427
		"	Zork z;\n" + 
31439
		"	^^^^\n" + 
31428
		"	^^^^\n" + 
31440
		"Zork cannot be resolved to a type\n" + 
31429
		"Zork cannot be resolved to a type\n" + 
Lines 34370-34385 Link Here
34370
		"	static <M extends String> Comparator<M> baz() {\n" + 
34359
		"	static <M extends String> Comparator<M> baz() {\n" + 
34371
		"	                  ^^^^^^\n" + 
34360
		"	                  ^^^^^^\n" + 
34372
		"The type parameter M should not be bounded by the final type String. Final types cannot be further extended\n" + 
34361
		"The type parameter M should not be bounded by the final type String. Final types cannot be further extended\n" + 
34373
		"----------\n" + 
34374
		"2. ERROR in ComparableComparator.java (at line 25)\n" + 
34375
		"	static Comparator BAR = ComparableComparator.bar();//0\n" + 
34376
		"	                                             ^^^\n" + 
34377
		"Bound mismatch: The generic method bar() of type ComparableComparator<T> is not applicable for the arguments (). The inferred type Comparable<Comparable<M>> is not a valid substitute for the bounded parameter <M extends Comparable<M>>\n" + 
34378
		"----------\n" + 
34379
		"3. ERROR in ComparableComparator.java (at line 27)\n" + 
34380
		"	static Object BAR2 = ComparableComparator.bar();//1a\n" + 
34381
		"	                                          ^^^\n" + 
34382
		"Bound mismatch: The generic method bar() of type ComparableComparator<T> is not applicable for the arguments (). The inferred type Comparable<Comparable<M>> is not a valid substitute for the bounded parameter <M extends Comparable<M>>\n" + 
34383
		"----------\n");
34362
		"----------\n");
34384
}
34363
}
34385
//https://bugs.eclipse.org/bugs/show_bug.cgi?id=158548
34364
//https://bugs.eclipse.org/bugs/show_bug.cgi?id=158548
Lines 41591-41601 Link Here
41591
			"    }\n" +
41570
			"    }\n" +
41592
			"}\n", // =================
41571
			"}\n", // =================
41593
		},
41572
		},
41594
		"----------\n" +
41573
		"----------\n" + 
41595
		"1. ERROR in X.java (at line 6)\n" +
41574
		"1. ERROR in X.java (at line 6)\n" + 
41596
		"	Object[] o  = throwE(objs);\n" +
41575
		"	Object[] o  = throwE(objs);\n" + 
41597
		"	              ^^^^^^\n" +
41576
		"	              ^^^^^^\n" + 
41598
		"Bound mismatch: The generic method throwE(Object...) of type X is not applicable for the arguments (Object[]). The inferred type Object[] is not a valid substitute for the bounded parameter <E extends Exception>\n" +
41577
		"Bound mismatch: The generic method throwE(Object...) of type X is not applicable for the arguments (Object[]). The inferred type Object[]&Exception is not a valid substitute for the bounded parameter <E extends Exception>\n" + 
41578
		"----------\n" + 
41579
		"2. ERROR in X.java (at line 6)\n" + 
41580
		"	Object[] o  = throwE(objs);\n" + 
41581
		"	              ^^^^^^^^^^^^\n" + 
41582
		"Type mismatch: cannot convert from Object[]&Exception to Object[]\n" + 
41599
		"----------\n");
41583
		"----------\n");
41600
}
41584
}
41601
//https://bugs.eclipse.org/bugs/show_bug.cgi?id=208030
41585
//https://bugs.eclipse.org/bugs/show_bug.cgi?id=208030
Lines 45140-45165 Link Here
45140
					"        }\n" +
45124
					"        }\n" +
45141
					"}\n", // =================
45125
					"}\n", // =================
45142
			},
45126
			},
45143
			"----------\n" +
45127
			"----------\n" + 
45144
			"1. ERROR in X.java (at line 8)\n" +
45128
			"1. ERROR in X.java (at line 8)\n" + 
45145
			"	<T extends N<T>> T foo3(String name, T value) {}\n" +
45129
			"	<T extends N<T>> T foo3(String name, T value) {}\n" + 
45146
			"	                   ^^^^^^^^^^^^^^^^^^^^^^^^^^\n" +
45130
			"	                   ^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + 
45147
			"This method must return a result of type T\n" +
45131
			"This method must return a result of type T\n" + 
45148
			"----------\n" +
45132
			"----------\n" + 
45149
			"2. ERROR in X.java (at line 15)\n" +
45133
			"2. ERROR in X.java (at line 15)\n" + 
45150
			"	new X().foo(\"HI\", null); // correctly report error\n" +
45134
			"	new X().foo(\"HI\", null); // correctly report error\n" + 
45151
			"	        ^^^\n" +
45135
			"	        ^^^\n" + 
45152
			"The method foo(String, String) is ambiguous for the type X\n" +
45136
			"The method foo(String, String) is ambiguous for the type X\n" + 
45153
			"----------\n" +
45137
			"----------\n" + 
45154
			"3. ERROR in X.java (at line 18)\n" +
45138
			"3. ERROR in X.java (at line 16)\n" + 
45155
			"	Thread t1 = foo3(\"HI\", null);\n" +
45139
			"	new X().foo2(\"HI\", null); // miss ambiguous error\n" + 
45156
			"	            ^^^^\n" +
45140
			"	        ^^^^\n" + 
45157
			"The method foo3(String, null) is undefined for the type Test\n" +
45141
			"The method foo2(String, String) is ambiguous for the type X\n" + 
45158
			"----------\n" +
45142
			"----------\n" + 
45159
			"4. ERROR in X.java (at line 19)\n" +
45143
			"4. ERROR in X.java (at line 18)\n" + 
45160
			"	Thread t2 = (Thread)foo3(\"HI\", null);\n" +
45144
			"	Thread t1 = foo3(\"HI\", null);\n" + 
45161
			"	                    ^^^^\n" +
45145
			"	            ^^^^\n" + 
45162
			"The method foo3(String, null) is undefined for the type Test\n" +
45146
			"The method foo3(String, null) is undefined for the type Test\n" + 
45147
			"----------\n" + 
45148
			"5. ERROR in X.java (at line 19)\n" + 
45149
			"	Thread t2 = (Thread)foo3(\"HI\", null);\n" + 
45150
			"	                    ^^^^\n" + 
45151
			"The method foo3(String, null) is undefined for the type Test\n" + 
45163
			"----------\n");
45152
			"----------\n");
45164
}
45153
}
45165
//https://bugs.eclipse.org/bugs/show_bug.cgi?id=229928 - variation
45154
//https://bugs.eclipse.org/bugs/show_bug.cgi?id=229928 - variation
Lines 45181-45197 Link Here
45181
					"}\n", // =================
45170
					"}\n", // =================
45182
			},
45171
			},
45183
			"----------\n" +
45172
			"----------\n" +
45184
			"1. ERROR in X.java (at line 8)\n" +
45173
			"1. ERROR in X.java (at line 9)\n" +
45185
			"	new X().foo2(\"HI\", null);\n" +
45186
			"	        ^^^^\n" +
45187
			"Bound mismatch: The generic method foo2(String, T) of type X is not applicable for the arguments (String, null). The inferred type N<N<T>> is not a valid substitute for the bounded parameter <T extends N<T>>\n" +
45188
			"----------\n" +
45189
			"2. ERROR in X.java (at line 9)\n" +
45190
			"	new X().<N<?>>foo2(\"HI\", null);\n" +
45174
			"	new X().<N<?>>foo2(\"HI\", null);\n" +
45191
			"	              ^^^^\n" +
45175
			"	              ^^^^\n" +
45192
			"Bound mismatch: The generic method foo2(String, T) of type X is not applicable for the arguments (String, null). The inferred type N<?> is not a valid substitute for the bounded parameter <T extends N<T>>\n" +
45176
			"Bound mismatch: The generic method foo2(String, T) of type X is not applicable for the arguments (String, null). The inferred type N<?> is not a valid substitute for the bounded parameter <T extends N<T>>\n" +
45193
			"----------\n" +
45177
			"----------\n" +
45194
			"3. ERROR in X.java (at line 10)\n" +
45178
			"2. ERROR in X.java (at line 10)\n" +
45195
			"	new X().<N<? extends N<?>>>foo2(\"HI\", null);\n" +
45179
			"	new X().<N<? extends N<?>>>foo2(\"HI\", null);\n" +
45196
			"	                           ^^^^\n" +
45180
			"	                           ^^^^\n" +
45197
			"Bound mismatch: The generic method foo2(String, T) of type X is not applicable for the arguments (String, null). The inferred type N<? extends N<?>> is not a valid substitute for the bounded parameter <T extends N<T>>\n" +
45181
			"Bound mismatch: The generic method foo2(String, T) of type X is not applicable for the arguments (String, null). The inferred type N<? extends N<?>> is not a valid substitute for the bounded parameter <T extends N<T>>\n" +
Lines 45199-45205 Link Here
45199
}
45183
}
45200
//https://bugs.eclipse.org/bugs/show_bug.cgi?id=229928 - variation
45184
//https://bugs.eclipse.org/bugs/show_bug.cgi?id=229928 - variation
45201
public void test1319() {
45185
public void test1319() {
45202
	this.runNegativeTest(
45186
	this.runConformTest(
45203
			new String[] {
45187
			new String[] {
45204
					"X.java", // =================
45188
					"X.java", // =================
45205
					"import java.util.List;\n" +
45189
					"import java.util.List;\n" +
Lines 45213-45228 Link Here
45213
					"        }\n" +
45197
					"        }\n" +
45214
					"}\n", // =================
45198
					"}\n", // =================
45215
			},
45199
			},
45216
			"----------\n" +
45200
			"");
45217
			"1. ERROR in X.java (at line 8)\n" +
45218
			"	new X().foo2(\"HI\", null, null, null);\n" +
45219
			"	        ^^^^\n" +
45220
			"Bound mismatch: The generic method foo2(String, U, T, W) of type X is not applicable for the arguments (String, null, null, null). The inferred type List<List<W>> is not a valid substitute for the bounded parameter <T extends List<U>>\n" +
45221
			"----------\n");
45222
}
45201
}
45223
//https://bugs.eclipse.org/bugs/show_bug.cgi?id=229928 - variation
45202
//https://bugs.eclipse.org/bugs/show_bug.cgi?id=229928 - variation
45224
public void test1320() {
45203
public void test1320() {
45225
	this.runNegativeTest(
45204
	this.runConformTest(
45226
			new String[] {
45205
			new String[] {
45227
					"X.java", // =================
45206
					"X.java", // =================
45228
					"import java.util.List;\n" +
45207
					"import java.util.List;\n" +
Lines 45236-45251 Link Here
45236
					"        }\n" +
45215
					"        }\n" +
45237
					"}\n", // =================
45216
					"}\n", // =================
45238
			},
45217
			},
45239
			"----------\n" +
45218
			"");
45240
			"1. ERROR in X.java (at line 8)\n" +
45241
			"	new X().foo2(\"HI\", null, null, null);\n" +
45242
			"	        ^^^^\n" +
45243
			"Bound mismatch: The generic method foo2(String, U, T, W) of type X is not applicable for the arguments (String, null, null, null). The inferred type List<List<W>> is not a valid substitute for the bounded parameter <T extends List<U>>\n" +
45244
			"----------\n");
45245
}
45219
}
45246
//https://bugs.eclipse.org/bugs/show_bug.cgi?id=229928 - variation
45220
//https://bugs.eclipse.org/bugs/show_bug.cgi?id=229928 - variation
45247
public void test1321() {
45221
public void test1321() {
45248
	this.runNegativeTest(
45222
	this.runConformTest(
45249
			new String[] {
45223
			new String[] {
45250
					"X.java", // =================
45224
					"X.java", // =================
45251
					"import java.util.List;\n" +
45225
					"import java.util.List;\n" +
Lines 45259-45270 Link Here
45259
					"        }\n" +
45233
					"        }\n" +
45260
					"}\n", // =================
45234
					"}\n", // =================
45261
			},
45235
			},
45262
			"----------\n" +
45236
			"");
45263
			"1. ERROR in X.java (at line 8)\n" +
45264
			"	new X().foo2(\"HI\", null, null, null);\n" +
45265
			"	        ^^^^\n" +
45266
			"Bound mismatch: The generic method foo2(String, U, T, W) of type X is not applicable for the arguments (String, null, null, null). The inferred type List<List<T>> is not a valid substitute for the bounded parameter <W extends List<U>>\n" +
45267
			"----------\n");
45268
}
45237
}
45269
//https://bugs.eclipse.org/bugs/show_bug.cgi?id=231094
45238
//https://bugs.eclipse.org/bugs/show_bug.cgi?id=231094
45270
public void test1322() {
45239
public void test1322() {
Lines 47212-47218 Link Here
47212
}
47181
}
47213
//https://bugs.eclipse.org/bugs/show_bug.cgi?id=174447
47182
//https://bugs.eclipse.org/bugs/show_bug.cgi?id=174447
47214
public void test1380() {
47183
public void test1380() {
47215
	this.runNegativeTest(
47184
	this.runConformTest(
47216
			new String[] {
47185
			new String[] {
47217
				"X.java", //-----------------------------------------------------------------------
47186
				"X.java", //-----------------------------------------------------------------------
47218
				"public class X {\n" + 
47187
				"public class X {\n" + 
Lines 47223-47234 Link Here
47223
				"    }\n" + 
47192
				"    }\n" + 
47224
				"}\n",//-----------------------------------------------------------------------
47193
				"}\n",//-----------------------------------------------------------------------
47225
			},
47194
			},
47226
			"----------\n" + 
47195
			"");
47227
			"1. ERROR in X.java (at line 5)\n" + 
47228
			"	f();\n" + 
47229
			"	^\n" + 
47230
			"Bound mismatch: The generic method f() of type X is not applicable for the arguments (). The inferred type Enum<Enum<E>> is not a valid substitute for the bounded parameter <E extends Enum<E>>\n" + 
47231
			"----------\n");
47232
}
47196
}
47233
//https://bugs.eclipse.org/bugs/show_bug.cgi?id=247953
47197
//https://bugs.eclipse.org/bugs/show_bug.cgi?id=247953
47234
public void test1381()  throws Exception {
47198
public void test1381()  throws Exception {
Lines 48237-48244 Link Here
48237
		"Syntax error, insert \")\" to complete Expression\n" + 
48201
		"Syntax error, insert \")\" to complete Expression\n" + 
48238
		"----------\n");
48202
		"----------\n");
48239
}
48203
}
48240
//https://bugs.eclipse.org/bugs/show_bug.cgi?id=242159
48204
// https://bugs.eclipse.org/bugs/show_bug.cgi?id=242159
48241
public void _test1404()  throws Exception {
48205
public void test1404()  throws Exception {
48242
	this.runNegativeTest(
48206
	this.runNegativeTest(
48243
		new String[] {
48207
		new String[] {
48244
			"X.java",
48208
			"X.java",
Lines 48255-48274 Link Here
48255
			"}\n",
48219
			"}\n",
48256
		},
48220
		},
48257
		"----------\n" + 
48221
		"----------\n" + 
48258
		"1. ERROR in X.java (at line 7)\n" + 
48222
		"1. WARNING in X.java (at line 8)\n" + 
48259
		"	bar(); // 0 rejected\n" + 
48260
		"	^^^\n" + 
48261
		"Bound mismatch: The generic method bar() of type X<A> is not applicable for the arguments (). The inferred type Comparable<Comparable<B>> is not a valid substitute for the bounded parameter <B extends Comparable<B>>\n" + 
48262
		"----------\n" + 
48263
		"2. WARNING in X.java (at line 8)\n" + 
48264
		"	X raw = bar(); // 1 accepted\n" + 
48223
		"	X raw = bar(); // 1 accepted\n" + 
48265
		"	^\n" + 
48224
		"	^\n" + 
48266
		"X is a raw type. References to generic type X<A> should be parameterized\n" + 
48225
		"X is a raw type. References to generic type X<A> should be parameterized\n" + 
48267
		"----------\n" + 
48268
		"3. ERROR in X.java (at line 9)\n" + 
48269
		"	X<?> wild = bar(); // 2 rejected\n" + 
48270
		"	            ^^^\n" + 
48271
		"Bound mismatch: The generic method bar() of type X<A> is not applicable for the arguments (). The inferred type Comparable<Comparable<B>> is not a valid substitute for the bounded parameter <B extends Comparable<B>>\n" + 
48272
		"----------\n");
48226
		"----------\n");
48273
}
48227
}
48274
//https://bugs.eclipse.org/bugs/show_bug.cgi?id=240807
48228
//https://bugs.eclipse.org/bugs/show_bug.cgi?id=240807
(-)src/org/eclipse/jdt/core/tests/compiler/regression/GenericsRegressionTest_1_7.java (-88 / +49 lines)
Lines 1170-1176 Link Here
1170
		"----------\n");
1170
		"----------\n");
1171
}
1171
}
1172
// https://bugs.eclipse.org/bugs/show_bug.cgi?id=346026
1172
// https://bugs.eclipse.org/bugs/show_bug.cgi?id=346026
1173
public void _test0030() {
1173
public void test0030() {
1174
	this.runNegativeTest(
1174
	this.runNegativeTest(
1175
		new String[] {
1175
		new String[] {
1176
			"X.java",
1176
			"X.java",
Lines 1181-1191 Link Here
1181
			"    X f = new X<>();\n" +
1181
			"    X f = new X<>();\n" +
1182
			"}\n"
1182
			"}\n"
1183
		},
1183
		},
1184
			"");
1184
		"----------\n" + 
1185
		"1. WARNING in X.java (at line 5)\n" + 
1186
		"	X f = new X<>();\n" + 
1187
		"	^\n" + 
1188
		"X is a raw type. References to generic type X<T> should be parameterized\n" + 
1189
		"----------\n");
1185
}
1190
}
1186
// https://bugs.eclipse.org/bugs/show_bug.cgi?id=346026
1191
// https://bugs.eclipse.org/bugs/show_bug.cgi?id=346026
1187
public void _test0031() {
1192
public void test0031() {
1188
	this.runNegativeTest(
1193
	this.runConformTest(
1189
		new String[] {
1194
		new String[] {
1190
			"X.java",
1195
			"X.java",
1191
			"class C {}\n" +
1196
			"class C {}\n" +
Lines 1198-1205 Link Here
1198
		"");
1203
		"");
1199
}
1204
}
1200
// https://bugs.eclipse.org/bugs/show_bug.cgi?id=346026
1205
// https://bugs.eclipse.org/bugs/show_bug.cgi?id=346026
1201
public void _test0032() {
1206
public void test0032() {
1202
	this.runNegativeTest(
1207
	this.runConformTest(
1203
		new String[] {
1208
		new String[] {
1204
			"X.java",
1209
			"X.java",
1205
			"class C {}\n" +
1210
			"class C {}\n" +
Lines 1214-1220 Link Here
1214
		"");
1219
		"");
1215
}
1220
}
1216
// https://bugs.eclipse.org/bugs/show_bug.cgi?id=346026
1221
// https://bugs.eclipse.org/bugs/show_bug.cgi?id=346026
1217
public void _test0033() {
1222
public void test0033() {
1218
	this.runNegativeTest(
1223
	this.runNegativeTest(
1219
		new String[] {
1224
		new String[] {
1220
			"X.java",
1225
			"X.java",
Lines 1227-1233 Link Here
1227
			"    X f2 = getX();\n" +
1232
			"    X f2 = getX();\n" +
1228
			"}\n"
1233
			"}\n"
1229
		},
1234
		},
1230
		"");
1235
		"----------\n" + 
1236
		"1. WARNING in X.java (at line 7)\n" + 
1237
		"	X f2 = getX();\n" + 
1238
		"	^\n" + 
1239
		"X is a raw type. References to generic type X<T> should be parameterized\n" + 
1240
		"----------\n");
1231
}
1241
}
1232
// https://bugs.eclipse.org/bugs/show_bug.cgi?id=345559
1242
// https://bugs.eclipse.org/bugs/show_bug.cgi?id=345559
1233
public void test0034() {
1243
public void test0034() {
Lines 1574-1677 Link Here
1574
		"Cannot infer elided type(s)\n" + 
1584
		"Cannot infer elided type(s)\n" + 
1575
		"----------\n");
1585
		"----------\n");
1576
}
1586
}
1577
//https://bugs.eclipse.org/bugs/show_bug.cgi?id=346026
1587
// https://bugs.eclipse.org/bugs/show_bug.cgi?id=341795
1578
public void _test0038() {
1588
public void test0038() {
1579
	this.runNegativeTest(
1589
	this.runConformTest(
1580
		new String[] {
1581
			"X.java",
1582
			"class C {}\n" +
1583
			"interface I {}\n" +
1584
			"public class X<T extends C & I> {\n" +
1585
			"    X() {}\n" +
1586
			"    X f = new X<>();\n" +
1587
			"}\n"
1588
		},
1589
		"----------\n" + 
1590
		"1. WARNING in X.java (at line 5)\n" + 
1591
		"	X f = new X<>();\n" + 
1592
		"	^\n" + 
1593
		"X is a raw type. References to generic type X<T> should be parameterized\n" + 
1594
		"----------\n");
1595
}
1596
//https://bugs.eclipse.org/bugs/show_bug.cgi?id=346026
1597
public void _test0039() {
1598
	this.runNegativeTest(
1599
		new String[] {
1600
			"X.java",
1601
			"class C {}\n" +
1602
			"interface I {}\n" +
1603
			"public class X<T extends C & I> {\n" +
1604
			"    X() {}\n" +
1605
			"    X<?> f = new X<>();\n" +
1606
			"    Zork z;\n" +
1607
			"}\n"
1608
		},
1609
		"----------\n" + 
1610
		"1. ERROR in X.java (at line 6)\n" + 
1611
		"	Zork z;\n" + 
1612
		"	^^^^\n" + 
1613
		"Zork cannot be resolved to a type\n" + 
1614
		"----------\n");
1615
}
1616
//https://bugs.eclipse.org/bugs/show_bug.cgi?id=346026
1617
public void _test0040() {
1618
	this.runNegativeTest(
1619
		new String[] {
1590
		new String[] {
1620
			"X.java",
1591
			"X.java",
1621
			"class C {}\n" +
1592
			"interface A {\n" +
1622
			"interface I {}\n" +
1593
			"    <T extends B & C> T getaMethod();\n" +
1623
			"public class X<T extends C & I> {\n" +
1594
			"    <T extends B & C> void setaMethod(T param);\n" +
1624
			"    static <U extends C & I> X<U> getX() {\n" +
1595
			"}\n" +
1625
			"        return null;\n" +
1596
			"class B {\n" +
1597
			"}\n" +
1598
			"interface C {\n" +
1599
			"}\n" +
1600
			"public class X {\n" +
1601
			"    public void someMethod(A aInstance) {\n" +
1602
			"        aInstance.getaMethod();\n" +
1626
			"    }\n" +
1603
			"    }\n" +
1627
			"    X<?> f2 = getX();\n" +
1628
			"    Zork z;\n" +
1629
			"}\n"
1604
			"}\n"
1630
		},
1605
		},
1631
		"----------\n" + 
1606
		"");
1632
		"1. ERROR in X.java (at line 8)\n" + 
1633
		"	Zork z;\n" + 
1634
		"	^^^^\n" + 
1635
		"Zork cannot be resolved to a type\n" + 
1636
		"----------\n");
1637
}
1607
}
1638
//https://bugs.eclipse.org/bugs/show_bug.cgi?id=346026
1608
// https://bugs.eclipse.org/bugs/show_bug.cgi?id=319436
1639
public void _test0041() {
1609
public void test0039() {
1640
	this.runNegativeTest(
1610
	this.runConformTest(
1641
		new String[] {
1611
		new String[] {
1642
			"X.java",
1612
			"X.java",
1643
			"class C {}\n" +
1613
			"import java.io.Serializable;\n" +
1644
			"interface I {}\n" +
1614
			"public class X {\n" +
1645
			"public class X<T extends C & I> {\n" +
1615
			"  public static void main(String[] args) {\n" +
1646
			"    static <U extends C & I> X<U> getX() {\n" +
1616
			"    createObject();\n" +
1647
			"        return null;\n" +
1617
			"  }\n" +
1648
			"    }\n" +
1618
			"  private static <T extends Comparable<?> & Serializable> T createObject() {\n" +
1649
			"    X f2 = getX();\n" +
1619
			"    return null;\n" +
1650
			"}\n"
1620
			"  }\n" +
1621
			"}\n" 
1651
		},
1622
		},
1652
		"----------\n" + 
1623
		"");
1653
		"1. WARNING in X.java (at line 7)\n" + 
1654
		"	X f2 = getX();\n" + 
1655
		"	^\n" + 
1656
		"X is a raw type. References to generic type X<T> should be parameterized\n" + 
1657
		"----------\n");
1658
}
1624
}
1659
public void _test0042() {
1625
public void test0042() {
1660
	this.runNegativeTest(
1626
	this.runNegativeTest(
1661
		new String[] {
1627
		new String[] {
1662
			"X.java",
1628
			"X.java",
1663
			"interface I<T> {}\n" +
1629
			"interface I<T> {}\n" +
1664
			"public class X{\n" +
1630
			"public class X {\n" +
1665
			"    <T extends I<T>> void m() { }\n" +
1631
			"    <T extends I<T>> void m() { }\n" +
1666
			"    { m(); } \n" +
1632
			"    { m(); } \n" +
1667
			"}\n"
1633
			"}\n"
1668
		},
1634
		},
1669
		"----------\n" + 
1635
		"");
1670
		"1. WARNING in X.java (at line 7)\n" + 
1671
		"	X f2 = getX();\n" + 
1672
		"	^\n" + 
1673
		"X is a raw type. References to generic type X<T> should be parameterized\n" + 
1674
		"----------\n");
1675
}
1636
}
1676
// https://bugs.eclipse.org/bugs/show_bug.cgi?id=345968
1637
// https://bugs.eclipse.org/bugs/show_bug.cgi?id=345968
1677
public void test0043() {
1638
public void test0043() {

Return to bug 242159