Summary: | The Eclipse Compiler incorrectly reports the field is defined in an inherited type and an enclosing scope. | ||
---|---|---|---|
Product: | [Eclipse Project] JDT | Reporter: | Raj Gunaratnam <rajanyorku> |
Component: | Core | Assignee: | Srikanth Sankaran <srikanth_sankaran> |
Status: | VERIFIED INVALID | QA Contact: | |
Severity: | major | ||
Priority: | P3 | CC: | kent_johnson, Olivier_Thomann, philippe_mulet |
Version: | 3.4 | ||
Target Milestone: | 3.5 M6 | ||
Hardware: | PC | ||
OS: | Windows XP | ||
Whiteboard: |
Description
Raj Gunaratnam
2008-10-08 17:03:34 EDT
The compliance level (1.3) emulates the corresponding JDK level. If you feed javac 1.3.1 with your testcase, you will also get an error: ClassA.java:10: _state is inherited from ClassA.ClassB and hides variable in outer class ClassA. An explicit 'this' qualifier must be used to select the d esired instance. _state = 0; //This gives a compilation error ^ Basically, the language evolved between 1.3 and 1.4 to privilege inherited over enclosing. This explains why a Javac 1.5 would compile it clean. Same for Eclipse compiler, if you set compliance above 1.3. If you look closely to the compliance preference page, you can see that there are actually 3 settings: 1. compliance 2. source level 3. target level 1. emulates the corresponding JDK 2. is equivalent to option -source for javac 3. is equivalent to option -target for javac So if all you care is to have a target JRE <= 1.3, then you can use: 1. Compliance = 1.4 2. Source = 1.3 3. Target = 1.2 (which are the defaults when toggling the Compliance to 1.4, and keep default source/target levels). Srikanth - pls add some regression test (FieldAccessTest) and close as invalid (since the expectation does not match the spec) The test should be using compliance check to set different expectation based on compliance level (e.g. LookupTest#test074) (In reply to comment #2) > Srikanth - pls add some regression test (FieldAccessTest) and close as invalid > (since the expectation does not match the spec) > The test should be using compliance check to set different expectation based on > compliance level (e.g. LookupTest#test074) There are numerous tests that elicit this diagnostic. In particular, org.eclipse.jdt.core.tests.compiler.regression.SuperTypeTest.test002() org.eclipse.jdt.core.tests.compiler.regression.SuperTypeTest.test003() org.eclipse.jdt.core.tests.compiler.regression.SuperTypeTest.test004() seem to test both the negative test (1.3) and conform test (1.4, 1.4+). These tests look adequate to me. Did you have any additional scenarios in mind ? Closing as Invalid for Srikanth Existing regression tests are sufficient Verified for 3.5M6 |