Bug 165069 - [1.5][compiler] incorrect field hiding
Summary: [1.5][compiler] incorrect field hiding
Status: VERIFIED FIXED
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Core (show other bugs)
Version: 3.3   Edit
Hardware: Macintosh Mac OS X - Carbon (unsup.)
: P3 minor (vote)
Target Milestone: 3.3 M4   Edit
Assignee: Philipe Mulet CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2006-11-18 08:03 EST by Julien Dufour CLA
Modified: 2007-07-29 09:21 EDT (History)
0 users

See Also:


Attachments
Proposed patch (5.68 KB, patch)
2006-11-20 07:31 EST, Philipe Mulet CLA
no flags Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Julien Dufour CLA 2006-11-18 08:03:08 EST
In the following sample, 'Organize imports' adds the useless static imports :


package sample;

import static sample.Test.TestEnum.V1;
import static sample.Test.TestEnum.V2;

public class Test<T> {
	public static enum TestEnum {
		V1,
		V2
	}

	public void test(final TestEnum value) {
		switch (value) {
			case V1:
			case V2:
		}
	}

	public void ref() {
		final TestEnum v1 = TestEnum.V1;
		final TestEnum v2 = TestEnum.V2;
	}
}


The confusion results from the combination of the switch statement, the embedded TestEnum class, and the generic Test class. Removing the switch statement (while keeping the other references to TestEnum), turning TestEnum into a top level class or removing the type parameter of Test makes the useless imports disappear.

Hopefully, those imports don't prevent compilation. However, the fields of the enum are reported to hide some other elements (ironically, they are hiding themselves) :

    The field Test<T>.TestEnum.V1 is hiding a field from type Test.TestEnum
Comment 1 Olivier Thomann CLA 2006-11-18 14:36:24 EST
Compiled with -warn:hiding reports:
----------
1. WARNING in D:\tests_sources\sample\Test.java (at line 8)
	V1,
	^^
The field Test<T>.TestEnum.V1 is hiding a field from type Test.TestEnum
----------
2. WARNING in D:\tests_sources\sample\Test.java (at line 9)
	V2
	^^
The field Test<T>.TestEnum.V2 is hiding a field from type Test.TestEnum
----------
2 problems (2 warnings)

Removing the two imports fixes it.
Comment 2 Olivier Thomann CLA 2006-11-18 14:39:41 EST
Bug 165081 has been added to track the unused import problem.
Comment 3 Philipe Mulet CLA 2006-11-20 07:31:53 EST
Created attachment 54166 [details]
Proposed patch
Comment 4 Philipe Mulet CLA 2006-11-20 07:34:02 EST
Added StaticImportTest#test047
Comment 5 Philipe Mulet CLA 2006-11-20 08:05:32 EST
Released for 3.3M4

Fixed
Comment 6 Olivier Thomann CLA 2006-12-11 15:51:32 EST
Verified for 3.3M4 with I20061211-1119
Comment 7 Eclipse Webmaster CLA 2007-07-29 09:21:10 EDT
Changing OS from Mac OS to Mac OS X as per bug 185991