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

Collapse All | Expand All

(-)compiler/org/eclipse/jdt/internal/compiler/lookup/FieldBinding.java (-2 / +2 lines)
Lines 108-115 Link Here
108
		// AND the invocationType and the declaringClass have a common enclosingType
108
		// AND the invocationType and the declaringClass have a common enclosingType
109
		receiverCheck: {
109
		receiverCheck: {
110
			if (receiverType != this.declaringClass) {
110
			if (receiverType != this.declaringClass) {
111
				// special tolerance for type variable direct bounds
111
				// special tolerance for type variable direct bounds, but only below 1.7 see: https://bugs.eclipse.org/bugs/show_bug.cgi?id=334622
112
				if (receiverType.isTypeVariable() && ((TypeVariableBinding) receiverType).isErasureBoundTo(this.declaringClass.erasure()))
112
				if (scope.compilerOptions().complianceLevel <= ClassFileConstants.JDK1_6 && receiverType.isTypeVariable() && ((TypeVariableBinding) receiverType).isErasureBoundTo(this.declaringClass.erasure()))
113
					break receiverCheck;
113
					break receiverCheck;
114
				return false;
114
				return false;
115
			}
115
			}
(-)compiler/org/eclipse/jdt/internal/compiler/lookup/MethodBinding.java (-2 / +2 lines)
Lines 287-294 Link Here
287
		// AND the invocationType and the declaringClass have a common enclosingType
287
		// AND the invocationType and the declaringClass have a common enclosingType
288
		receiverCheck: {
288
		receiverCheck: {
289
			if (receiverType != this.declaringClass) {
289
			if (receiverType != this.declaringClass) {
290
				// special tolerance for type variable direct bounds
290
				// special tolerance for type variable direct bounds, but only if compliance <= 1.6, see: https://bugs.eclipse.org/bugs/show_bug.cgi?id=334622
291
				if (receiverType.isTypeVariable() && ((TypeVariableBinding) receiverType).isErasureBoundTo(this.declaringClass.erasure()))
291
				if (scope.compilerOptions().complianceLevel <= ClassFileConstants.JDK1_6 && receiverType.isTypeVariable() && ((TypeVariableBinding) receiverType).isErasureBoundTo(this.declaringClass.erasure()))
292
					break receiverCheck;
292
					break receiverCheck;
293
				return false;
293
				return false;
294
			}
294
			}
(-)src/org/eclipse/jdt/core/tests/compiler/regression/GenericsRegressionTest.java (+147 lines)
Lines 15-20 Link Here
15
15
16
import junit.framework.Test;
16
import junit.framework.Test;
17
17
18
import org.eclipse.jdt.internal.compiler.classfmt.ClassFileConstants;
18
import org.eclipse.jdt.internal.compiler.impl.CompilerOptions;
19
import org.eclipse.jdt.internal.compiler.impl.CompilerOptions;
19
20
20
public class GenericsRegressionTest extends AbstractComparableTest {
21
public class GenericsRegressionTest extends AbstractComparableTest {
Lines 1157-1160 Link Here
1157
			true,
1158
			true,
1158
			customOptions);
1159
			customOptions);
1159
}
1160
}
1161
// https://bugs.eclipse.org/bugs/show_bug.cgi?id=334622 (private access - different packages)
1162
public void test334622a() {
1163
	this.runNegativeTest(
1164
			new String[] {
1165
					"p/X.java",
1166
					"package p;\n" +
1167
					"public class X {\n" +
1168
					"    private Object foo;\n" +
1169
					"}\n",
1170
					"q/Y.java",
1171
					"package q;\n" +
1172
					"import p.X;\n" +
1173
					"public class Y {\n" +
1174
					"    public <T extends X> void test(T t) {\n" +
1175
					"        System.out.println(t.foo);\n" +
1176
					"    }\n" +
1177
					"    Zork z;\n" +
1178
					"}\n"
1179
			},
1180
			"----------\n" + 
1181
			"1. WARNING in p\\X.java (at line 3)\n" + 
1182
			"	private Object foo;\n" + 
1183
			"	               ^^^\n" + 
1184
			"The value of the field X.foo is not used\n" + 
1185
			"----------\n" + 
1186
			"----------\n" + 
1187
			"1. ERROR in q\\Y.java (at line 5)\n" + 
1188
			"	System.out.println(t.foo);\n" + 
1189
			"	                     ^^^\n" + 
1190
			"The field X.foo is not visible\n" + 
1191
			"----------\n" + 
1192
			"2. ERROR in q\\Y.java (at line 7)\n" + 
1193
			"	Zork z;\n" + 
1194
			"	^^^^\n" + 
1195
			"Zork cannot be resolved to a type\n" + 
1196
			"----------\n");
1197
}
1198
// https://bugs.eclipse.org/bugs/show_bug.cgi?id=334622 (private access - same package)
1199
public void test334622b() {
1200
	this.runNegativeTest(
1201
			new String[] {
1202
					"p/X.java",
1203
					"package p;\n" +
1204
					"public class X {\n" +
1205
					"    private Object foo;\n" +
1206
					"}\n",
1207
					"p/Y.java",
1208
					"package p;\n" +
1209
					"public class Y {\n" +
1210
					"    public <T extends X> void test(T t) {\n" +
1211
					"        System.out.println(t.foo);\n" +
1212
					"    }\n" +
1213
					"    Zork z;\n" +
1214
					"}\n"
1215
			},
1216
			"----------\n" + 
1217
			"1. WARNING in p\\X.java (at line 3)\n" + 
1218
			"	private Object foo;\n" + 
1219
			"	               ^^^\n" + 
1220
			"The value of the field X.foo is not used\n" + 
1221
			"----------\n" + 
1222
			"----------\n" + 
1223
			"1. ERROR in p\\Y.java (at line 4)\n" + 
1224
			"	System.out.println(t.foo);\n" + 
1225
			"	                     ^^^\n" + 
1226
			"The field X.foo is not visible\n" + 
1227
			"----------\n" + 
1228
			"2. ERROR in p\\Y.java (at line 6)\n" + 
1229
			"	Zork z;\n" + 
1230
			"	^^^^\n" + 
1231
			"Zork cannot be resolved to a type\n" + 
1232
			"----------\n");
1233
}
1234
// https://bugs.eclipse.org/bugs/show_bug.cgi?id=334622 (member of type variable shouldn't contain private members of class constituting intersection type)
1235
public void test334622c() {
1236
	this.runNegativeTest(
1237
			new String[] {
1238
					"X.java",
1239
					"public class X {\n" +
1240
					"    private Object foo;\n" +
1241
					"    public <T extends X> void test(T t) {\n" +
1242
					"        System.out.println(t.foo);\n" +
1243
					"        Zork z;\n" +
1244
					"    }\n" +
1245
					"}\n"
1246
			},
1247
			this.complianceLevel <= ClassFileConstants.JDK1_6 ?
1248
			"----------\n" + 
1249
			"1. ERROR in X.java (at line 5)\n" + 
1250
			"	Zork z;\n" + 
1251
			"	^^^^\n" + 
1252
			"Zork cannot be resolved to a type\n" + 
1253
			"----------\n" : 
1254
				
1255
			// 1.7+ output.	
1256
			"----------\n" + 
1257
			"1. WARNING in X.java (at line 2)\n" + 
1258
			"	private Object foo;\n" + 
1259
			"	               ^^^\n" + 
1260
			"The value of the field X.foo is not used\n" + 
1261
			"----------\n" + 
1262
			"2. ERROR in X.java (at line 4)\n" + 
1263
			"	System.out.println(t.foo);\n" + 
1264
			"	                     ^^^\n" + 
1265
			"The field X.foo is not visible\n" + 
1266
			"----------\n" + 
1267
			"3. ERROR in X.java (at line 5)\n" + 
1268
			"	Zork z;\n" + 
1269
			"	^^^^\n" + 
1270
			"Zork cannot be resolved to a type\n" + 
1271
			"----------\n");
1272
}
1273
//https://bugs.eclipse.org/bugs/show_bug.cgi?id=334622 (member of type variable shouldn't contain private members of class constituting intersection type)
1274
public void test334622d() {
1275
	this.runNegativeTest(
1276
			new String[] {
1277
					"X.java",
1278
					"public class X {\n" +
1279
					"    private Object foo() { return null; }\n" +
1280
					"    public <T extends X> void test(T t) {\n" +
1281
					"        t.foo();\n" +
1282
					"        Zork z;\n" +
1283
					"    }\n" +
1284
					"}\n"
1285
			},
1286
			this.complianceLevel <= ClassFileConstants.JDK1_6 ?
1287
			"----------\n" + 
1288
			"1. ERROR in X.java (at line 5)\n" + 
1289
			"	Zork z;\n" + 
1290
			"	^^^^\n" + 
1291
			"Zork cannot be resolved to a type\n" + 
1292
			"----------\n" : 
1293
				
1294
			// 1.7+ output.	
1295
			"----------\n" + 
1296
			"1. ERROR in X.java (at line 4)\n" + 
1297
			"	t.foo();\n" + 
1298
			"	  ^^^\n" + 
1299
			"The method foo() from the type X is not visible\n" + 
1300
			"----------\n" + 
1301
			"2. ERROR in X.java (at line 5)\n" + 
1302
			"	Zork z;\n" + 
1303
			"	^^^^\n" + 
1304
			"Zork cannot be resolved to a type\n" + 
1305
			"----------\n");
1306
}
1160
}
1307
}

Return to bug 334622