View | Details | Raw Unified | Return to bug 169049
Collapse All | Expand All

(-)src/org/eclipse/jdt/core/tests/compiler/regression/GenericTypeTest.java (+161 lines)
Lines 38973-38976 Link Here
38973
		},
38973
		},
38974
		"");
38974
		"");
38975
}
38975
}
38976
//https://bugs.eclipse.org/bugs/show_bug.cgi?id=169049
38977
public void test1168() {
38978
	this.runNegativeTest(
38979
		new String[] {
38980
			"example/Container.java",
38981
			"package example;\n" +
38982
			"class A<E> {}\n" + 
38983
			"class B<E> extends A<E> {}\n" + 
38984
			"\n" + 
38985
			"public interface Container<T, U extends T, V extends A<T>> {\n" + 
38986
			"	<T1, U1 extends T1, V1 extends A<T1>> void f(\n" + 
38987
			"			Container<?, ?, ?> a, \n" + 
38988
			"			Container<?, ? extends T1, ?> b, \n" + 
38989
			"			Container<T1, U1, V1> c, \n" + 
38990
			"			Container<? extends T1, ? extends U1, ? extends V1> d, \n" + 
38991
			"			Container<T1, ? extends U1, ? extends V1> e, \n" + 
38992
			"			Container<T1, ? extends U1, A<T>> f, \n" + 
38993
			"			Container<T1, U1, A<U1>> g,\n" + 
38994
			"			Container<T1, U1, A<T1>> h);\n" + 
38995
			"}\n", // =================
38996
		},
38997
		"----------\n" + 
38998
		"1. ERROR in example\\Container.java (at line 12)\n" + 
38999
		"	Container<T1, ? extends U1, A<T>> f, \n" + 
39000
		"	                            ^\n" + 
39001
		"Bound mismatch: The type A<T> is not a valid substitute for the bounded parameter <V extends A<T>> of the type Container<T,U,V>\n" + 
39002
		"----------\n" + 
39003
		"2. ERROR in example\\Container.java (at line 13)\n" + 
39004
		"	Container<T1, U1, A<U1>> g,\n" + 
39005
		"	                  ^\n" + 
39006
		"Bound mismatch: The type A<U1> is not a valid substitute for the bounded parameter <V extends A<T>> of the type Container<T,U,V>\n" + 
39007
		"----------\n");
39008
}
39009
//https://bugs.eclipse.org/bugs/show_bug.cgi?id=169049 - variation
39010
public void test1169() {
39011
	this.runNegativeTest(
39012
		new String[] {
39013
			"example/Container2.java",
39014
			"package example;\n" +
39015
			"class A<E> {}\n" + 
39016
			"class B<E> extends A<E> {}\n" + 
39017
			"\n" + 
39018
			"public interface Container2<T, U extends T, V extends A<? extends T>> {\n" + 
39019
			"	<T1, U1 extends T1, V1 extends A<? extends T1>> void g(\n" + 
39020
			"			Container2<?, ?, ?> a, \n" + 
39021
			"			Container2<?, ? extends T1, ?> b, \n" + 
39022
			"			Container2<T1, U1, V1> c, \n" + 
39023
			"			Container2<? extends T1, ? extends U1, ? extends V1> d, \n" + 
39024
			"			Container2<T1, ? extends U1, ? extends V1> e, \n" + 
39025
			"			Container2<T1, ? extends U1, A<T>> f, \n" + 
39026
			"			Container2<T1, U1, A<U1>> g, \n" + 
39027
			"			Container2<? extends T1, U1, ? extends V1> h);\n" + 
39028
			"\n" + 
39029
			"}\n", // =================
39030
		},
39031
		"----------\n" + 
39032
		"1. ERROR in example\\Container2.java (at line 12)\n" + 
39033
		"	Container2<T1, ? extends U1, A<T>> f, \n" + 
39034
		"	                             ^\n" + 
39035
		"Bound mismatch: The type A<T> is not a valid substitute for the bounded parameter <V extends A<? extends T>> of the type Container2<T,U,V>\n" + 
39036
		"----------\n");
39037
}
39038
//https://bugs.eclipse.org/bugs/show_bug.cgi?id=169049 - variation
39039
public void test1170() {
39040
	this.runNegativeTest(
39041
		new String[] {
39042
			"example/Container3.java",
39043
			"package example;\n" +
39044
			"class A<E> {}\n" + 
39045
			"class B<E> extends A<E> {}\n" + 
39046
			"class A<E> {}\n" + 
39047
			"class B<E> extends A<E> {}\n" + 
39048
			"\n" + 
39049
			"public interface Container3<T, U extends T, V extends A<? super T>> {\n" + 
39050
			"	<T1, U1 extends T1, V1 extends A<? super T1>> void g(\n" + 
39051
			"			Container3<?, ?, ?> a, \n" + 
39052
			"			Container3<?, ? extends T1, ?> b, \n" + 
39053
			"			Container3<T1, U1, V1> c, \n" + 
39054
			"			Container3<? extends T1, ? extends U1, ? extends V1> d, \n" + 
39055
			"			Container3<T1, ? extends U1, ? extends V1> e, \n" + 
39056
			"			Container3<T1, ? extends U1, A<T>> f, \n" + 
39057
			"			Container3<T1, U1, A<U1>> g, \n" + 
39058
			"			Container3<? extends T1, U1, ? extends V1> h, \n" + 
39059
			"			Container3<T1, ? extends U1, A<? super T>> i, \n" + 
39060
			"			Container3<T1, ? extends U1, A> j);\n" + 
39061
			"\n" + 
39062
			"	<T1, U1 extends T1, V1 extends B<? super T1>> void h(\n" + 
39063
			"			Container3<?, ?, ?> a, \n" + 
39064
			"			Container3<?, ? extends T1, ?> b, \n" + 
39065
			"			Container3<T1, U1, V1> c, \n" + 
39066
			"			Container3<? extends T1, ? extends U1, ? extends V1> d, \n" + 
39067
			"			Container3<T1, ? extends U1, ? extends V1> e, \n" + 
39068
			"			Container3<T1, ? extends U1, B<T>> f, \n" + 
39069
			"			Container3<T1, U1, B<U1>> g, \n" + 
39070
			"			Container3<? extends T1, U1, ? extends V1> h, \n" + 
39071
			"			Container3<T1, ? extends U1, B<? super T>> i, \n" + 
39072
			"			Container3<T1, ? extends U1, B> j);\n" + 
39073
			"}\n", // =================
39074
		},
39075
		"----------\n" + 
39076
		"1. ERROR in example\\Container3.java (at line 4)\n" + 
39077
		"	class A<E> {}\n" + 
39078
		"	      ^\n" + 
39079
		"The type A is already defined\n" + 
39080
		"----------\n" + 
39081
		"2. ERROR in example\\Container3.java (at line 5)\n" + 
39082
		"	class B<E> extends A<E> {}\n" + 
39083
		"	      ^\n" + 
39084
		"The type B is already defined\n" + 
39085
		"----------\n" + 
39086
		"3. ERROR in example\\Container3.java (at line 14)\n" + 
39087
		"	Container3<T1, ? extends U1, A<T>> f, \n" + 
39088
		"	                             ^\n" + 
39089
		"Bound mismatch: The type A<T> is not a valid substitute for the bounded parameter <V extends A<? super T>> of the type Container3<T,U,V>\n" + 
39090
		"----------\n" + 
39091
		"4. ERROR in example\\Container3.java (at line 15)\n" + 
39092
		"	Container3<T1, U1, A<U1>> g, \n" + 
39093
		"	                   ^\n" + 
39094
		"Bound mismatch: The type A<U1> is not a valid substitute for the bounded parameter <V extends A<? super T>> of the type Container3<T,U,V>\n" + 
39095
		"----------\n" + 
39096
		"5. ERROR in example\\Container3.java (at line 17)\n" + 
39097
		"	Container3<T1, ? extends U1, A<? super T>> i, \n" + 
39098
		"	                             ^\n" + 
39099
		"Bound mismatch: The type A<? super T> is not a valid substitute for the bounded parameter <V extends A<? super T>> of the type Container3<T,U,V>\n" + 
39100
		"----------\n" + 
39101
		"6. WARNING in example\\Container3.java (at line 18)\n" + 
39102
		"	Container3<T1, ? extends U1, A> j);\n" + 
39103
		"	                             ^\n" + 
39104
		"A is a raw type. References to generic type A<E> should be parameterized\n" + 
39105
		"----------\n" + 
39106
		"7. ERROR in example\\Container3.java (at line 18)\n" + 
39107
		"	Container3<T1, ? extends U1, A> j);\n" + 
39108
		"	                             ^\n" + 
39109
		"Bound mismatch: The type A is not a valid substitute for the bounded parameter <V extends A<? super T>> of the type Container3<T,U,V>\n" + 
39110
		"----------\n" + 
39111
		"8. ERROR in example\\Container3.java (at line 26)\n" + 
39112
		"	Container3<T1, ? extends U1, B<T>> f, \n" + 
39113
		"	                             ^\n" + 
39114
		"Bound mismatch: The type B<T> is not a valid substitute for the bounded parameter <V extends A<? super T>> of the type Container3<T,U,V>\n" + 
39115
		"----------\n" + 
39116
		"9. ERROR in example\\Container3.java (at line 27)\n" + 
39117
		"	Container3<T1, U1, B<U1>> g, \n" + 
39118
		"	                   ^\n" + 
39119
		"Bound mismatch: The type B<U1> is not a valid substitute for the bounded parameter <V extends A<? super T>> of the type Container3<T,U,V>\n" + 
39120
		"----------\n" + 
39121
		"10. ERROR in example\\Container3.java (at line 29)\n" + 
39122
		"	Container3<T1, ? extends U1, B<? super T>> i, \n" + 
39123
		"	                             ^\n" + 
39124
		"Bound mismatch: The type B<? super T> is not a valid substitute for the bounded parameter <V extends A<? super T>> of the type Container3<T,U,V>\n" + 
39125
		"----------\n" + 
39126
		"11. WARNING in example\\Container3.java (at line 30)\n" + 
39127
		"	Container3<T1, ? extends U1, B> j);\n" + 
39128
		"	                             ^\n" + 
39129
		"B is a raw type. References to generic type B<E> should be parameterized\n" + 
39130
		"----------\n" + 
39131
		"12. ERROR in example\\Container3.java (at line 30)\n" + 
39132
		"	Container3<T1, ? extends U1, B> j);\n" + 
39133
		"	                             ^\n" + 
39134
		"Bound mismatch: The type B is not a valid substitute for the bounded parameter <V extends A<? super T>> of the type Container3<T,U,V>\n" + 
39135
		"----------\n");
39136
}
38976
}
39137
}
(-)compiler/org/eclipse/jdt/internal/compiler/lookup/TypeVariableBinding.java (-15 / +11 lines)
Lines 127-150 Link Here
127
		}
127
		}
128
		boolean unchecked = false;
128
		boolean unchecked = false;
129
		if (this.superclass.id != TypeIds.T_JavaLangObject) {
129
		if (this.superclass.id != TypeIds.T_JavaLangObject) {
130
			TypeBinding superType = this.superclass;
130
			TypeBinding substitutedSuperType = hasSubstitution ? Scope.substitute(substitution, this.superclass) : this.superclass;
131
			if (superType != argumentType) { // check identity before substituting (104649)
131
			if (!argumentType.isCompatibleWith(substitutedSuperType)) {
132
				TypeBinding substitutedSuperType = hasSubstitution ? Scope.substitute(substitution, superType) : superType;
132
			    return TypeConstants.MISMATCH;
133
				if (!argumentType.isCompatibleWith(substitutedSuperType)) {
133
			}
134
				    return TypeConstants.MISMATCH;
134
			TypeBinding match = argumentType.findSuperTypeWithSameErasure(substitutedSuperType);
135
				}
135
			if (match != null){
136
				TypeBinding match = argumentType.findSuperTypeWithSameErasure(substitutedSuperType);
136
				// Enum#RAW is not a substitute for <E extends Enum<E>> (86838)
137
				if (match != null){
137
				if (match.isRawType() && substitutedSuperType.isBoundParameterizedType())
138
					// Enum#RAW is not a substitute for <E extends Enum<E>> (86838)
138
					unchecked = true;
139
					if (match.isRawType() && substitutedSuperType.isBoundParameterizedType())
140
						unchecked = true;
141
				}
142
			}
139
			}
143
		}
140
		}
144
	    for (int i = 0, length = this.superInterfaces.length; i < length; i++) {
141
	    for (int i = 0, length = this.superInterfaces.length; i < length; i++) {
145
	    	TypeBinding superType = this.superInterfaces[i];
142
			TypeBinding substitutedSuperType = hasSubstitution ? Scope.substitute(substitution, this.superInterfaces[i]) : this.superInterfaces[i];
146
	    	if (superType != argumentType) { // check identity before substituting (104649)
143
	    	if (substitutedSuperType != argumentType) { // check identity before substituting (104649)
147
				TypeBinding substitutedSuperType = hasSubstitution ? Scope.substitute(substitution, superType) : superType;
148
				if (!argumentType.isCompatibleWith(substitutedSuperType)) {
144
				if (!argumentType.isCompatibleWith(substitutedSuperType)) {
149
				    return TypeConstants.MISMATCH;
145
				    return TypeConstants.MISMATCH;
150
				}
146
				}

Return to bug 169049