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

(-)src/org/eclipse/jdt/core/tests/compiler/regression/AmbiguousMethodTest.java (-13 / +153 lines)
Lines 2894-2923 Link Here
2894
		"	               ^\n" +
2894
		"	               ^\n" +
2895
		"The return types are incompatible for the inherited methods J.a(), I.a()\n" +
2895
		"The return types are incompatible for the inherited methods J.a(), I.a()\n" +
2896
		"----------\n" +
2896
		"----------\n" +
2897
		"4. ERROR in Y.java (at line 15)\n" +
2897
		"4. ERROR in Y.java (at line 20)\n" +
2898
		"	byte a = a();\n" +
2899
		"	         ^\n" +
2900
		"The method a() is ambiguous for the type Y\n" +
2901
		"----------\n" +
2902
		"5. ERROR in Y.java (at line 20)\n" +
2903
		"	abstract class Y2 extends X implements J, I {\n" +
2898
		"	abstract class Y2 extends X implements J, I {\n" +
2904
		"	               ^^\n" +
2899
		"	               ^^\n" +
2905
		"The return types are incompatible for the inherited methods J.c(), X.c()\n" +
2900
		"The return types are incompatible for the inherited methods J.c(), X.c()\n" +
2906
		"----------\n" +
2901
		"----------\n" +
2907
		"6. ERROR in Y.java (at line 20)\n" +
2902
		"5. ERROR in Y.java (at line 20)\n" +
2908
		"	abstract class Y2 extends X implements J, I {\n" +
2903
		"	abstract class Y2 extends X implements J, I {\n" +
2909
		"	               ^^\n" +
2904
		"	               ^^\n" +
2910
		"The return types are incompatible for the inherited methods I.b(), X.b()\n" +
2905
		"The return types are incompatible for the inherited methods I.b(), X.b()\n" +
2911
		"----------\n" +
2906
		"----------\n" +
2912
		"7. ERROR in Y.java (at line 20)\n" +
2907
		"6. ERROR in Y.java (at line 20)\n" +
2913
		"	abstract class Y2 extends X implements J, I {\n" +
2908
		"	abstract class Y2 extends X implements J, I {\n" +
2914
		"	               ^^\n" +
2909
		"	               ^^\n" +
2915
		"The return types are incompatible for the inherited methods I.a(), J.a()\n" +
2910
		"The return types are incompatible for the inherited methods I.a(), J.a()\n" +
2916
		"----------\n" +
2917
		"8. ERROR in Y.java (at line 22)\n" +
2918
		"	byte a = a();\n" +
2919
		"	         ^\n" +
2920
		"The method a() is ambiguous for the type Y2\n" +
2921
		"----------\n"
2911
		"----------\n"
2922
	);
2912
	);
2923
}
2913
}
Lines 3066-3069 Link Here
3066
		"----------\n"
3056
		"----------\n"
3067
	);
3057
	);
3068
}
3058
}
3059
3060
//https://bugs.eclipse.org/bugs/show_bug.cgi?id=268837
3061
public void test076() {
3062
	this.runNegativeTest(
3063
		new String[] {
3064
			"X.java",
3065
			"interface I<E> {\n" +
3066
			"	I<String> a();\n" +
3067
			"	I<String> b();\n" +
3068
			"	<T1> I<T1> c();\n" +
3069
			"}\n" +
3070
			"interface J<E> extends I<E> {\n" +
3071
			"	J<String> a();\n" +
3072
			"	<U> J<String> b();\n" +
3073
			"	<T2> J<T2> c();\n" +
3074
			"}\n" +
3075
			"class X {\n" +
3076
			"	void a(J<Integer> ints) {\n" +
3077
			"		ints.a();\n" +
3078
			"		J<String> a = ints.a();\n" +
3079
			"		J<Integer> b = ints.a();\n" + // incompatible types
3080
			"		J<Object> c = ints.a();\n" + // incompatible types
3081
			"		J d = ints.a();\n" +
3082
			"		I<String> e = ints.a();\n" +
3083
			"		I<Integer> f = ints.a();\n" + // incompatible types
3084
			"		I<Object> g = ints.a();\n" + // incompatible types
3085
			"		I h = ints.a();\n" +
3086
			"	}\n" +
3087
			"	void b(J<Integer> ints) {\n" +
3088
			"		ints.b();\n" + // ambiguous
3089
			"		J<String> a = ints.b();\n" + // ambiguous
3090
			"		J<Integer> b = ints.b();\n" + // ambiguous
3091
			"		J<Object> c = ints.b();\n" + // ambiguous
3092
			"		J d = ints.b();\n" + // ambiguous
3093
			"		I<String> e = ints.b();\n" + // ambiguous
3094
			"		I<Integer> f = ints.b();\n" + // ambiguous
3095
			"		I<Object> g = ints.b();\n" + // ambiguous
3096
			"		I h = ints.b();\n" + // ambiguous
3097
			"	}\n" +
3098
			"	void c(J<Integer> ints) {\n" +
3099
			"		ints.c();\n" +
3100
			"		J<String> a = ints.c();\n" +
3101
			"		J<Integer> b = ints.c();\n" +
3102
			"		J<Object> c = ints.c();\n" +
3103
			"		J d = ints.c();\n" +
3104
			"		I<String> e = ints.c();\n" +
3105
			"		I<Integer> f = ints.c();\n" +
3106
			"		I<Object> g = ints.c();\n" +
3107
			"		I h = ints.c();\n" +
3108
			"	}\n" +
3109
			"}"
3110
		},
3111
		"----------\n" + 
3112
		"1. ERROR in X.java (at line 15)\n" + 
3113
		"	J<Integer> b = ints.a();\n" + 
3114
		"	               ^^^^^^^^\n" + 
3115
		"Type mismatch: cannot convert from J<String> to J<Integer>\n" + 
3116
		"----------\n" + 
3117
		"2. ERROR in X.java (at line 16)\n" + 
3118
		"	J<Object> c = ints.a();\n" + 
3119
		"	              ^^^^^^^^\n" + 
3120
		"Type mismatch: cannot convert from J<String> to J<Object>\n" + 
3121
		"----------\n" + 
3122
		"3. WARNING in X.java (at line 17)\n" + 
3123
		"	J d = ints.a();\n" + 
3124
		"	^\n" + 
3125
		"J is a raw type. References to generic type J<E> should be parameterized\n" + 
3126
		"----------\n" + 
3127
		"4. ERROR in X.java (at line 19)\n" + 
3128
		"	I<Integer> f = ints.a();\n" + 
3129
		"	               ^^^^^^^^\n" + 
3130
		"Type mismatch: cannot convert from J<String> to I<Integer>\n" + 
3131
		"----------\n" + 
3132
		"5. ERROR in X.java (at line 20)\n" + 
3133
		"	I<Object> g = ints.a();\n" + 
3134
		"	              ^^^^^^^^\n" + 
3135
		"Type mismatch: cannot convert from J<String> to I<Object>\n" + 
3136
		"----------\n" + 
3137
		"6. WARNING in X.java (at line 21)\n" + 
3138
		"	I h = ints.a();\n" + 
3139
		"	^\n" + 
3140
		"I is a raw type. References to generic type I<E> should be parameterized\n" + 
3141
		"----------\n" + 
3142
		"7. ERROR in X.java (at line 24)\n" + 
3143
		"	ints.b();\n" + 
3144
		"	     ^\n" + 
3145
		"The method b() is ambiguous for the type J<Integer>\n" + 
3146
		"----------\n" + 
3147
		"8. ERROR in X.java (at line 25)\n" + 
3148
		"	J<String> a = ints.b();\n" + 
3149
		"	                   ^\n" + 
3150
		"The method b() is ambiguous for the type J<Integer>\n" + 
3151
		"----------\n" + 
3152
		"9. ERROR in X.java (at line 26)\n" + 
3153
		"	J<Integer> b = ints.b();\n" + 
3154
		"	                    ^\n" + 
3155
		"The method b() is ambiguous for the type J<Integer>\n" + 
3156
		"----------\n" + 
3157
		"10. ERROR in X.java (at line 27)\n" + 
3158
		"	J<Object> c = ints.b();\n" + 
3159
		"	                   ^\n" + 
3160
		"The method b() is ambiguous for the type J<Integer>\n" + 
3161
		"----------\n" + 
3162
		"11. WARNING in X.java (at line 28)\n" + 
3163
		"	J d = ints.b();\n" + 
3164
		"	^\n" + 
3165
		"J is a raw type. References to generic type J<E> should be parameterized\n" + 
3166
		"----------\n" + 
3167
		"12. ERROR in X.java (at line 28)\n" + 
3168
		"	J d = ints.b();\n" + 
3169
		"	           ^\n" + 
3170
		"The method b() is ambiguous for the type J<Integer>\n" + 
3171
		"----------\n" + 
3172
		"13. ERROR in X.java (at line 29)\n" + 
3173
		"	I<String> e = ints.b();\n" + 
3174
		"	                   ^\n" + 
3175
		"The method b() is ambiguous for the type J<Integer>\n" + 
3176
		"----------\n" + 
3177
		"14. ERROR in X.java (at line 30)\n" + 
3178
		"	I<Integer> f = ints.b();\n" + 
3179
		"	                    ^\n" + 
3180
		"The method b() is ambiguous for the type J<Integer>\n" + 
3181
		"----------\n" + 
3182
		"15. ERROR in X.java (at line 31)\n" + 
3183
		"	I<Object> g = ints.b();\n" + 
3184
		"	                   ^\n" + 
3185
		"The method b() is ambiguous for the type J<Integer>\n" + 
3186
		"----------\n" + 
3187
		"16. WARNING in X.java (at line 32)\n" + 
3188
		"	I h = ints.b();\n" + 
3189
		"	^\n" + 
3190
		"I is a raw type. References to generic type I<E> should be parameterized\n" + 
3191
		"----------\n" + 
3192
		"17. ERROR in X.java (at line 32)\n" + 
3193
		"	I h = ints.b();\n" + 
3194
		"	           ^\n" + 
3195
		"The method b() is ambiguous for the type J<Integer>\n" + 
3196
		"----------\n" + 
3197
		"18. WARNING in X.java (at line 39)\n" + 
3198
		"	J d = ints.c();\n" + 
3199
		"	^\n" + 
3200
		"J is a raw type. References to generic type J<E> should be parameterized\n" + 
3201
		"----------\n" + 
3202
		"19. WARNING in X.java (at line 43)\n" + 
3203
		"	I h = ints.c();\n" + 
3204
		"	^\n" + 
3205
		"I is a raw type. References to generic type I<E> should be parameterized\n" + 
3206
		"----------\n"
3207
	);
3208
}
3069
}
3209
}
(-)compiler/org/eclipse/jdt/internal/compiler/lookup/Scope.java (-4 / +6 lines)
Lines 3705-3715 Link Here
3705
						if (original2 == null || !original.areParameterErasuresEqual(original2))
3705
						if (original2 == null || !original.areParameterErasuresEqual(original2))
3706
							continue nextSpecific; // current does not override next
3706
							continue nextSpecific; // current does not override next
3707
						if (original.returnType != original2.returnType) {
3707
						if (original.returnType != original2.returnType) {
3708
							if (!current.returnType.isCompatibleWith(next.returnType)) 
3708
							if (current instanceof ParameterizedGenericMethodBinding) {
3709
								if (original.returnType.erasure().findSuperTypeOriginatingFrom(original2.returnType.erasure()) == null)
3710
									continue nextSpecific;
3711
							} else if (!current.returnType.isCompatibleWith(next.returnType)) { 
3709
								continue nextSpecific;
3712
								continue nextSpecific;
3710
							if (original.returnType.erasure().findSuperTypeOriginatingFrom(original2.returnType.erasure()) == null)
3713
							}
3711
								continue nextSpecific;
3714
							// continue with original 15.12.2.5
3712
							// continue with original 15.12.2
3713
						}
3715
						}
3714
						if (shouldIntersectExceptions && original2.declaringClass.isInterface()) {
3716
						if (shouldIntersectExceptions && original2.declaringClass.isInterface()) {
3715
							if (current.thrownExceptions != next.thrownExceptions) {
3717
							if (current.thrownExceptions != next.thrownExceptions) {

Return to bug 268837