Bug 93341

Summary: compiler: "field defined in an inherited type and an enclosing scope" error
Product: [Eclipse Project] JDT Reporter: Fabrizio Giustina <fgiust>
Component: CoreAssignee: JDT-Core-Inbox <jdt-core-inbox>
Status: CLOSED INVALID QA Contact:
Severity: critical    
Priority: P3    
Version: 3.1   
Target Milestone: 3.1 M7   
Hardware: PC   
OS: Windows XP   
Whiteboard:

Description Fabrizio Giustina CLA 2005-04-30 04:30:42 EDT
Eclipse can't compile a class which javac is able to compile without errors when :
- the same field is defined in a parent class and an inner class [1]
- another inner class [2] extends the previous inner class [1] and uses the field

A test case is easier than an explaination: the following class compiles with
javac (tested on jdk1.5, windows):

public class TestDuplicateField
{
    public int simpleField;
    public TestDuplicateField()
    {
        simpleField = 1;
    }
    public class InnerOne
    {
        public int simpleField;
        public InnerOne()
        {
            simpleField = 1;
        }
    }
    public class InnerTwo extends InnerOne
    {
        public InnerTwo()
        {
            simpleField = 1;
        }
    }
}

Eclipse reports the following error:
"The field simpleType is defined in an inherited type and an enclosing scope"

Tested on Eclipse 3.1M6
Comment 1 Philipe Mulet CLA 2005-05-02 05:56:26 EDT
Which compliance are you using ?

I suspect you use 1.3 compliance, where the error is legite. Checked javac 1.3
which agrees with us:
TestDuplicateField
.java:14: simpleField is inherited from TestDuplicateField
.InnerOne and hides variable in outer class TestDuplicateField
.  An explicit 'this' qualifier must be used to select the desired instance.
                        simpleField = 1;
                        ^
1 error

In compliance 1.4 and above, no error is reported. Only a warning (optional) is
surfaced to flag the field override.
Comment 2 Fabrizio Giustina CLA 2005-05-02 06:22:45 EDT
verified, I was using the default settings with 1.3 compliance. 
Sorry for the invalid report and thanks.
Comment 3 Philipe Mulet CLA 2005-05-02 07:57:20 EDT
No problem, and thanks for checking.