Bug 263877 - [1.5][compiler] forward reference error flagged within enum
Summary: [1.5][compiler] forward reference error flagged within enum
Status: VERIFIED FIXED
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Core (show other bugs)
Version: 3.5   Edit
Hardware: PC Windows XP
: P3 normal with 1 vote (vote)
Target Milestone: 3.5 M6   Edit
Assignee: Philipe Mulet CLA
QA Contact:
URL:
Whiteboard:
Keywords:
: 266466 266500 275736 (view as bug list)
Depends on:
Blocks:
 
Reported: 2009-02-05 17:16 EST by Ryan Fong CLA
Modified: 2011-06-20 13:42 EDT (History)
8 users (show)

See Also:


Attachments
Proposed patch (4.03 KB, patch)
2009-02-06 07:00 EST, Philipe Mulet CLA
no flags Details | Diff
Better patch (7.55 KB, patch)
2009-02-06 07:33 EST, Philipe Mulet CLA
no flags Details | Diff
Proposed patch for 3.4 (6.93 KB, patch)
2009-02-06 07:34 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 Ryan Fong CLA 2009-02-05 17:16:07 EST
Build ID: I20090202-1535

Steps To Reproduce:
The error "Cannot reference a field before it is defined" appears in the Java compiler of Eclipse 3.5M5 (I20090202-1535).  This same code compiles correctly in Eclipse 3.4.1 (M20080911-1700) and javac 1.6.0_11.

In the code below, it appears on lines 3 & 4 where Days.OFFSET is used during construction of the enum values.  Moving the final OFFSET definition above the enum causes token errors.

More information:
public enum Days
{
    Monday("Mon", Days.OFFSET + 0),    // error here
    Tuesday("Tue", Days.OFFSET + 1);   // and here
    
    public static final int OFFSET = 0;  // cannot move this above, else more errors
    
    Days(String abbr, int index) {
    }
}
Comment 1 Olivier Thomann CLA 2009-02-05 19:39:26 EST
Added disabled regression test:
org.eclipse.jdt.core.tests.compiler.regression.EnumTest#_test170
Comment 2 Philipe Mulet CLA 2009-02-06 06:34:44 EST
Only single name forward references to OFFSET should be complained against. Qualified ones should be tolerated (resulting in using default value).
Comment 3 Philipe Mulet CLA 2009-02-06 06:42:28 EST
likely a consequence of fix for bug 255452
Comment 4 Philipe Mulet CLA 2009-02-06 07:00:01 EST
Created attachment 124952 [details]
Proposed patch
Comment 5 Philipe Mulet CLA 2009-02-06 07:02:13 EST
The check for forward references inside Enum introduced with bug 255452 was slightly wrong. It should only complain for enum constants, as opposed to all fields declared inside enums...

Since fix for bug 255452 was also backported for 3.4.2, we should fix this one there as well. Unfortunately, 3.4.2 is done already.
Comment 6 Philipe Mulet CLA 2009-02-06 07:33:13 EST
Created attachment 124954 [details]
Better patch

includes a change for EnumTest#test169 which is improved by the change
Comment 7 Philipe Mulet CLA 2009-02-06 07:34:40 EST
Created attachment 124955 [details]
Proposed patch for 3.4
Comment 8 Philipe Mulet CLA 2009-02-06 09:46:09 EST
Released for 3.5M6
Fixed
Comment 9 Philipe Mulet CLA 2009-02-06 09:46:36 EST
Released in 3.4.x stream (post 3.4.2)
Comment 10 Olivier Thomann CLA 2009-02-27 08:30:25 EST
*** Bug 266466 has been marked as a duplicate of this bug. ***
Comment 11 Kent Johnson CLA 2009-02-27 11:17:24 EST
*** Bug 266500 has been marked as a duplicate of this bug. ***
Comment 12 Kent Johnson CLA 2009-03-10 10:28:01 EDT
Verified for 3.5M6 using I20090310-0100
Comment 13 Olivier Thomann CLA 2009-03-12 09:04:35 EDT
*** Bug 268308 has been marked as a duplicate of this bug. ***
Comment 14 Kent Johnson CLA 2009-03-19 14:10:58 EDT
*** Bug 269388 has been marked as a duplicate of this bug. ***
Comment 15 Thomas Richter CLA 2009-03-20 05:03:26 EDT
I got it with update to M20090211-1700 and I want to get it off by same way.
Could you please set the target milestone to the next coming update.
Comment 16 Philipe Mulet CLA 2009-03-20 06:14:50 EDT
What do you mean ? It is already marked with proper milestone.
Comment 17 max schroeder CLA 2009-03-20 06:26:22 EDT
(In reply to comment #16)
> What do you mean ? It is already marked with proper milestone.

I wouldn't call this a proper schedule for a real defect without any workarounds other than changing our code (which is not an option for an bug in the IDE).
And as long as "revert configuration" seems broken for almost all installations in this company, downgrading to 3.4.1 was a real pain ** *** ***. 
Comment 18 Nobody - feel free to take it CLA 2009-03-20 06:32:13 EDT
I'd like to echo the sentiment of previous comment (#17). The IDE is fundamentally broken and there are no plans to put out a 3.4.3? We have to wait until June '09 for 3.5 before the compiler will actually work?
Comment 19 Robert Konigsberg CLA 2009-04-22 11:42:50 EDT
I additionally agree with this sentiment. We have several engineers reporting this problem, and a point release would be great.
Comment 20 Philipe Mulet CLA 2009-05-08 09:17:51 EDT
I did deliver the fix to 3.4 stream, so we could construct a patch for it.
It should be posted at http://www.eclipse.org/jdt/core/r3.4/index.php#UPDATES
but I do not see it presently.

We will publish one asap.
Comment 21 Frederic Fusier CLA 2009-05-15 04:50:09 EDT
*** Bug 275736 has been marked as a duplicate of this bug. ***
Comment 22 Marcello Teodori CLA 2009-05-21 05:54:27 EDT
any ETA about when the fix backport to 3.4.x will be released? I'm using also Flex Builder so upgrading to 3.5 won't be an option for the time needed to Adobe to upgrade that plugin

thanks for any info
Comment 23 Olivier Thomann CLA 2009-05-21 08:49:40 EDT
Install the zip file:
http://www.eclipse.org/jdt/core/patches/patch.zip
into your dropins folder and restart.

This will install a version of JDT/Core that contains the fix.
Comment 24 Marcello Teodori CLA 2009-05-21 09:07:01 EDT
(In reply to comment #23)
> Install the zip file:
> http://www.eclipse.org/jdt/core/patches/patch.zip
> into your dropins folder and restart.
> 
> This will install a version of JDT/Core that contains the fix.
> 

Thanks Olivier! Now everything works fine!