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

Collapse All | Expand All

(-)src/org/eclipse/jdt/core/tests/compiler/regression/GenericTypeTest.java (+77 lines)
Lines 49455-49458 Link Here
49455
             ""
49455
             ""
49456
     );
49456
     );
49457
}
49457
}
49458
//https://bugs.eclipse.org/bugs/show_bug.cgi?id=159851
49459
public void test1450() {
49460
	this.runNegativeTest(
49461
		new String[] {
49462
			"X.java",
49463
			"import java.util.*;\n" +
49464
			"class A {}\n" +
49465
			"class B<T extends A> {}\n" +
49466
			"class X<T extends ArrayList<B<Integer>>> extends TreeMap<Integer, B<String>> {}\n" +
49467
			"\n" +
49468
			"class D<T> {}\n" +
49469
			"class E<T extends Number> {}\n" +
49470
			"class Y<T> extends E<D<T>> {}",
49471
		},
49472
		"----------\n" + 
49473
		"1. WARNING in X.java (at line 4)\n" + 
49474
		"	class X<T extends ArrayList<B<Integer>>> extends TreeMap<Integer, B<String>> {}\n" + 
49475
		"	      ^\n" + 
49476
		"The serializable class X does not declare a static final serialVersionUID field of type long\n" + 
49477
		"----------\n" + 
49478
		"2. ERROR in X.java (at line 4)\n" + 
49479
		"	class X<T extends ArrayList<B<Integer>>> extends TreeMap<Integer, B<String>> {}\n" + 
49480
		"	                              ^^^^^^^\n" + 
49481
		"Bound mismatch: The type Integer is not a valid substitute for the bounded parameter <T extends A> of the type B<T>\n" + 
49482
		"----------\n" + 
49483
		"3. ERROR in X.java (at line 4)\n" + 
49484
		"	class X<T extends ArrayList<B<Integer>>> extends TreeMap<Integer, B<String>> {}\n" + 
49485
		"	                                                                    ^^^^^^\n" + 
49486
		"Bound mismatch: The type String is not a valid substitute for the bounded parameter <T extends A> of the type B<T>\n" + 
49487
		"----------\n" + 
49488
		"4. ERROR in X.java (at line 8)\n" + 
49489
		"	class Y<T> extends E<D<T>> {}\n" + 
49490
		"	                     ^\n" + 
49491
		"Bound mismatch: The type D<T> is not a valid substitute for the bounded parameter <T extends Number> of the type E<T>\n" + 
49492
		"----------\n"
49493
	);
49494
}
49495
//https://bugs.eclipse.org/bugs/show_bug.cgi?id=159851
49496
public void test1451() {
49497
	this.runNegativeTest(
49498
		new String[] {
49499
			"X.java",
49500
			"class A<T> {}\n" +
49501
			"class B<T2 extends Number> {}\n" +
49502
			"class C<T3, T4> {}\n" +
49503
			"class X<T1, T2> extends C<A<A<B<T1>>>, A<B<T2>>> {}\n" +
49504
			"class Y<T> extends A<A<B<T>>> {}\n" +
49505
			"class Z<T> extends C<B<T>, A<B<T>>> {}",
49506
		},
49507
		"----------\n" + 
49508
		"1. ERROR in X.java (at line 4)\n" + 
49509
		"	class X<T1, T2> extends C<A<A<B<T1>>>, A<B<T2>>> {}\n" + 
49510
		"	                                ^^\n" + 
49511
		"Bound mismatch: The type T1 is not a valid substitute for the bounded parameter <T2 extends Number> of the type B<T2>\n" + 
49512
		"----------\n" + 
49513
		"2. ERROR in X.java (at line 4)\n" + 
49514
		"	class X<T1, T2> extends C<A<A<B<T1>>>, A<B<T2>>> {}\n" + 
49515
		"	                                           ^^\n" + 
49516
		"Bound mismatch: The type T2 is not a valid substitute for the bounded parameter <T2 extends Number> of the type B<T2>\n" + 
49517
		"----------\n" + 
49518
		"3. ERROR in X.java (at line 5)\n" + 
49519
		"	class Y<T> extends A<A<B<T>>> {}\n" + 
49520
		"	                         ^\n" + 
49521
		"Bound mismatch: The type T is not a valid substitute for the bounded parameter <T2 extends Number> of the type B<T2>\n" + 
49522
		"----------\n" + 
49523
		"4. ERROR in X.java (at line 6)\n" + 
49524
		"	class Z<T> extends C<B<T>, A<B<T>>> {}\n" + 
49525
		"	                       ^\n" + 
49526
		"Bound mismatch: The type T is not a valid substitute for the bounded parameter <T2 extends Number> of the type B<T2>\n" + 
49527
		"----------\n" + 
49528
		"5. ERROR in X.java (at line 6)\n" + 
49529
		"	class Z<T> extends C<B<T>, A<B<T>>> {}\n" + 
49530
		"	                               ^\n" + 
49531
		"Bound mismatch: The type T is not a valid substitute for the bounded parameter <T2 extends Number> of the type B<T2>\n" + 
49532
		"----------\n"
49533
	);
49534
}
49458
}
49535
}
(-)compiler/org/eclipse/jdt/internal/compiler/ast/ParameterizedSingleTypeReference.java (-2 / +3 lines)
Lines 231-239 Link Here
231
231
232
    	ParameterizedTypeBinding parameterizedType = scope.environment().createParameterizedType(currentOriginal, argTypes, enclosingType);
232
    	ParameterizedTypeBinding parameterizedType = scope.environment().createParameterizedType(currentOriginal, argTypes, enclosingType);
233
		// check argument type compatibility
233
		// check argument type compatibility
234
		if (checkBounds) { // otherwise will do it in Scope.connectTypeVariables() or generic method resolution
234
		if (checkBounds) // otherwise will do it in Scope.connectTypeVariables() or generic method resolution
235
			parameterizedType.boundCheck(scope, this.typeArguments);
235
			parameterizedType.boundCheck(scope, this.typeArguments);
236
		}
236
		else
237
			scope.rememberTypeReference(this);
237
		if (isTypeUseDeprecated(parameterizedType, scope))
238
		if (isTypeUseDeprecated(parameterizedType, scope))
238
			reportDeprecatedType(parameterizedType, scope);
239
			reportDeprecatedType(parameterizedType, scope);
239
240
(-)compiler/org/eclipse/jdt/internal/compiler/ast/ParameterizedQualifiedTypeReference.java (+2 lines)
Lines 261-266 Link Here
261
				// check argument type compatibility
261
				// check argument type compatibility
262
				if (checkBounds) // otherwise will do it in Scope.connectTypeVariables() or generic method resolution
262
				if (checkBounds) // otherwise will do it in Scope.connectTypeVariables() or generic method resolution
263
					parameterizedType.boundCheck(scope, args);
263
					parameterizedType.boundCheck(scope, args);
264
				else
265
					scope.rememberTypeReference(this);
264
				qualifyingType = parameterizedType;
266
				qualifyingType = parameterizedType;
265
		    } else {
267
		    } else {
266
				ReferenceBinding currentOriginal = (ReferenceBinding)currentType.original();
268
				ReferenceBinding currentOriginal = (ReferenceBinding)currentType.original();
(-)compiler/org/eclipse/jdt/internal/compiler/lookup/Scope.java (+12 lines)
Lines 3907-3912 Link Here
3907
		return null;
3907
		return null;
3908
	}
3908
	}
3909
3909
3910
	public void rememberTypeReference(TypeReference typeRef) {
3911
		if (this.kind == CLASS_SCOPE) {
3912
			ClassScope classScope = (ClassScope) this;
3913
			if (classScope.typeReferences == null) {
3914
				classScope.typeReferences = new ArrayList(3);
3915
				classScope.typeReferences.add(typeRef);
3916
			} else if (!classScope.typeReferences.contains(typeRef)) {
3917
				classScope.typeReferences.add(typeRef);
3918
			}
3919
		}
3920
	}
3921
3910
	// start position in this scope - for ordering scopes vs. variables
3922
	// start position in this scope - for ordering scopes vs. variables
3911
	int startIndex() {
3923
	int startIndex() {
3912
		return 0;
3924
		return 0;
(-)compiler/org/eclipse/jdt/internal/compiler/lookup/ClassScope.java (-13 / +5 lines)
Lines 32-41 Link Here
32
32
33
	public TypeDeclaration referenceContext;
33
	public TypeDeclaration referenceContext;
34
	public TypeReference superTypeReference;
34
	public TypeReference superTypeReference;
35
	java.util.ArrayList typeReferences;
35
36
36
	public ClassScope(Scope parent, TypeDeclaration context) {
37
	public ClassScope(Scope parent, TypeDeclaration context) {
37
		super(Scope.CLASS_SCOPE, parent);
38
		super(Scope.CLASS_SCOPE, parent);
38
		this.referenceContext = context;
39
		this.referenceContext = context;
40
		this.typeReferences = null; // initialized if required
39
	}
41
	}
40
42
41
	void buildAnonymousTypeBinding(SourceTypeBinding enclosingType, ReferenceBinding supertype) {
43
	void buildAnonymousTypeBinding(SourceTypeBinding enclosingType, ReferenceBinding supertype) {
Lines 813-831 Link Here
813
815
814
	// Perform deferred bound checks for parameterized type references (only done after hierarchy is connected)
816
	// Perform deferred bound checks for parameterized type references (only done after hierarchy is connected)
815
	public void  checkParameterizedTypeBounds() {
817
	public void  checkParameterizedTypeBounds() {
816
		TypeReference superclass = this.referenceContext.superclass;
818
		for (int i = 0, l = this.typeReferences == null ? 0 : this.typeReferences.size(); i < l; i++)
817
		if (superclass != null)
819
			((TypeReference) this.typeReferences.get(i)).checkBounds(this);
818
			superclass.checkBounds(this);
820
		this.typeReferences = null;
819
820
		TypeReference[] superinterfaces = this.referenceContext.superInterfaces;
821
		if (superinterfaces != null)
822
			for (int i = 0, length = superinterfaces.length; i < length; i++)
823
				superinterfaces[i].checkBounds(this);
824
825
		TypeParameter[] typeParameters = this.referenceContext.typeParameters;
826
		if (typeParameters != null)
827
			for (int i = 0, paramLength = typeParameters.length; i < paramLength; i++)
828
				typeParameters[i].checkBounds(this);
829
821
830
		ReferenceBinding[] memberTypes = this.referenceContext.binding.memberTypes;
822
		ReferenceBinding[] memberTypes = this.referenceContext.binding.memberTypes;
831
		if (memberTypes != null && memberTypes != Binding.NO_MEMBER_TYPES)
823
		if (memberTypes != null && memberTypes != Binding.NO_MEMBER_TYPES)

Return to bug 159851