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

Collapse All | Expand All

(-)compiler/org/eclipse/jdt/internal/compiler/lookup/Scope.java (-1 / +3 lines)
Lines 1688-1694 Link Here
1688
											}
1688
											}
1689
											if (foundField.isValidBinding())
1689
											if (foundField.isValidBinding())
1690
												// if a valid field was found, complain when another is found in an 'immediate' enclosing type (that is, not inherited)
1690
												// if a valid field was found, complain when another is found in an 'immediate' enclosing type (that is, not inherited)
1691
												if (foundField.declaringClass != fieldBinding.declaringClass)
1691
												// but only if "valid field" was inherited in the first place.
1692
												if (foundField.declaringClass != fieldBinding.declaringClass &&
1693
												    foundField.declaringClass != foundActualReceiverType) // https://bugs.eclipse.org/bugs/show_bug.cgi?id=316956
1692
													// i.e. have we found the same field - do not trust field identity yet
1694
													// i.e. have we found the same field - do not trust field identity yet
1693
													return new ProblemFieldBinding(
1695
													return new ProblemFieldBinding(
1694
														foundField, // closest match
1696
														foundField, // closest match
(-)src/org/eclipse/jdt/core/tests/compiler/regression/LookupTest.java (+147 lines)
Lines 3311-3316 Link Here
3311
		"The field A.B.length is not visible\n" + 
3311
		"The field A.B.length is not visible\n" + 
3312
		"----------\n");
3312
		"----------\n");
3313
}
3313
}
3314
// https://bugs.eclipse.org/bugs/show_bug.cgi?id=316956
3315
public void test103() {
3316
	Map options = getCompilerOptions();
3317
	CompilerOptions compOptions = new CompilerOptions(options);
3318
	if (compOptions.complianceLevel < ClassFileConstants.JDK1_4) return;
3319
	this.runNegativeTest(
3320
		new String[] {
3321
			"A.java",//------------------------------
3322
			"public class A {\n" +
3323
			"	  private int x;\n" +
3324
			"	  static class B {\n" +
3325
			"	    private int x;\n" +
3326
			"	    private C c = new C() {\n" +
3327
			"	      void foo() {\n" +
3328
			"	        x = 3;\n" +
3329
			"	      }\n" +
3330
			"	    };\n" +
3331
			"	  }\n" +
3332
			"	  static class C {\n" +
3333
			"	    private int x;\n" +
3334
			"	  }\n" +
3335
			"	}\n",
3336
		},
3337
		"----------\n" + 
3338
		"1. WARNING in A.java (at line 2)\n" + 
3339
		"	private int x;\n" + 
3340
		"	            ^\n" + 
3341
		"The field A.x is never read locally\n" + 
3342
		"----------\n" + 
3343
		"2. WARNING in A.java (at line 4)\n" + 
3344
		"	private int x;\n" + 
3345
		"	            ^\n" + 
3346
		"The field A.B.x is never read locally\n" + 
3347
		"----------\n" + 
3348
		"3. WARNING in A.java (at line 5)\n" + 
3349
		"	private C c = new C() {\n" + 
3350
		"	          ^\n" + 
3351
		"The field A.B.c is never read locally\n" + 
3352
		"----------\n" + 
3353
		"4. WARNING in A.java (at line 6)\n" + 
3354
		"	void foo() {\n" + 
3355
		"	     ^^^^^\n" + 
3356
		"The method foo() from the type new A.C(){} is never used locally\n" + 
3357
		"----------\n" + 
3358
		"5. WARNING in A.java (at line 7)\n" + 
3359
		"	x = 3;\n" + 
3360
		"	^\n" + 
3361
		"Write access to enclosing field A.B.x is emulated by a synthetic accessor method\n" + 
3362
		"----------\n" + 
3363
		"6. WARNING in A.java (at line 12)\n" + 
3364
		"	private int x;\n" + 
3365
		"	            ^\n" + 
3366
		"The field A.C.x is never read locally\n" + 
3367
		"----------\n");
3368
}
3369
// https://bugs.eclipse.org/bugs/show_bug.cgi?id=316956
3370
public void test104() {
3371
	Map options = getCompilerOptions();
3372
	CompilerOptions compOptions = new CompilerOptions(options);
3373
	if (compOptions.complianceLevel < ClassFileConstants.JDK1_4) return;
3374
	this.runNegativeTest(
3375
		new String[] {
3376
			"A.java",//------------------------------
3377
			"public class A {\n" +
3378
			"	  private int x;\n" +
3379
			"	  static class B {\n" +
3380
			"	    private int x;\n" +
3381
			"	    private C c = new C() {\n" +
3382
			"	      void foo() {\n" +
3383
			"	        x = 3;\n" +
3384
			"	      }\n" +
3385
			"	    };\n" +
3386
			"	  }\n" +
3387
			"	  static class C {\n" +
3388
			"	    public int x;\n" +
3389
			"	  }\n" +
3390
			"	}\n",
3391
		},
3392
		"----------\n" + 
3393
		"1. WARNING in A.java (at line 2)\n" + 
3394
		"	private int x;\n" + 
3395
		"	            ^\n" + 
3396
		"The field A.x is never read locally\n" + 
3397
		"----------\n" + 
3398
		"2. WARNING in A.java (at line 4)\n" + 
3399
		"	private int x;\n" + 
3400
		"	            ^\n" + 
3401
		"The field A.B.x is never read locally\n" + 
3402
		"----------\n" + 
3403
		"3. WARNING in A.java (at line 5)\n" + 
3404
		"	private C c = new C() {\n" + 
3405
		"	          ^\n" + 
3406
		"The field A.B.c is never read locally\n" + 
3407
		"----------\n" + 
3408
		"4. WARNING in A.java (at line 6)\n" + 
3409
		"	void foo() {\n" + 
3410
		"	     ^^^^^\n" + 
3411
		"The method foo() from the type new A.C(){} is never used locally\n" + 
3412
		"----------\n");
3413
}
3414
//https://bugs.eclipse.org/bugs/show_bug.cgi?id=316956
3415
public void test105() {
3416
	Map options = getCompilerOptions();
3417
	CompilerOptions compOptions = new CompilerOptions(options);
3418
	if (compOptions.complianceLevel < ClassFileConstants.JDK1_4) return;
3419
	this.runNegativeTest(
3420
		new String[] {
3421
			"A.java",//------------------------------
3422
			"public class A {\n" +
3423
			"	  private int x;\n" +
3424
			"	  private C c = new C() {\n" +
3425
			"	    void foo() {\n" +
3426
			"	      x = 3;\n" +
3427
			"	    }\n" +
3428
			"	  };\n" +
3429
			"	  static class C {\n" +
3430
			"	    private int x;\n" +
3431
			"	  }\n" +
3432
			"	 }\n",
3433
		},
3434
		"----------\n" + 
3435
		"1. WARNING in A.java (at line 2)\n" + 
3436
		"	private int x;\n" + 
3437
		"	            ^\n" + 
3438
		"The field A.x is never read locally\n" + 
3439
		"----------\n" + 
3440
		"2. WARNING in A.java (at line 3)\n" + 
3441
		"	private C c = new C() {\n" + 
3442
		"	          ^\n" + 
3443
		"The field A.c is never read locally\n" + 
3444
		"----------\n" + 
3445
		"3. WARNING in A.java (at line 4)\n" + 
3446
		"	void foo() {\n" + 
3447
		"	     ^^^^^\n" + 
3448
		"The method foo() from the type new A.C(){} is never used locally\n" + 
3449
		"----------\n" + 
3450
		"4. WARNING in A.java (at line 5)\n" + 
3451
		"	x = 3;\n" + 
3452
		"	^\n" + 
3453
		"Write access to enclosing field A.x is emulated by a synthetic accessor method\n" + 
3454
		"----------\n" + 
3455
		"5. WARNING in A.java (at line 9)\n" + 
3456
		"	private int x;\n" + 
3457
		"	            ^\n" + 
3458
		"The field A.C.x is never read locally\n" + 
3459
		"----------\n");
3460
}
3314
public static Class testClass() {	return LookupTest.class;
3461
public static Class testClass() {	return LookupTest.class;
3315
}
3462
}
3316
}
3463
}

Return to bug 316956