Bug 93341 - compiler: "field defined in an inherited type and an enclosing scope" error
Summary: compiler: "field defined in an inherited type and an enclosing scope" error
Status: CLOSED INVALID
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Core (show other bugs)
Version: 3.1   Edit
Hardware: PC Windows XP
: P3 critical (vote)
Target Milestone: 3.1 M7   Edit
Assignee: JDT-Core-Inbox CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2005-04-30 04:30 EDT by Fabrizio Giustina CLA
Modified: 2005-05-02 07:57 EDT (History)
0 users

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
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.