Bug 275736 - REGRESSION - code with legal forward reference does not compile
Summary: REGRESSION - code with legal forward reference does not compile
Status: VERIFIED DUPLICATE of bug 263877
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Core (show other bugs)
Version: 3.4.2   Edit
Hardware: PC Windows XP
: P3 blocker (vote)
Target Milestone: 3.5 M6   Edit
Assignee: JDT-Core-Inbox CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2009-05-11 17:07 EDT by Daniel CLA
Modified: 2009-05-15 04:51 EDT (History)
1 user (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Daniel CLA 2009-05-11 17:07:49 EDT
Build ID: M20090211-1700

Steps To Reproduce:
The following sample code compiles in Eclipse 3.4.0 build I20080617-2000, but not in 3.4.2 build M20090211-1700:

public enum BugTest {
    SAMPLE(TEST);
    
    private static final int TEST = 1;
    
    int x;
    
    BugTest(int x) {
        this.x = x;
    }
}

It fails with the error "Cannot reference a field before it is defined".

More information:
According to page 202 of the JLS:

"One subtlety here is that, at run time, static variables that are final and that
are initialized with compile-time constant values are initialized first."

Therefore, the sample code should compile, since the forward reference is to a compile-time constant.  (And, as I mentioned, it compiled in earlier versions of Eclipse.)
Comment 1 Olivier Thomann CLA 2009-05-11 17:44:23 EDT
In fact the reference needs to be qualified in order to be used in a forward reference.
So this code compiles fine:
public enum X {
    SAMPLE(X.TEST);

    private static final int TEST = 1;

    int x;

    X(int x) {
        this.x = x;
    }
}

but the code in comment 0 should report an error.
Now this doesn't solve the problem with 3.4.2 that has a bug.
See bug 263877.

*** This bug has been marked as a duplicate of bug 255452 ***
Comment 2 Daniel CLA 2009-05-11 18:00:53 EDT
Yes, the code that you provided is actually the code that I meant to submit (with the qualified reference).  That code still doesn't compile for me in 3.4.2.

Is that case also covered by #255452?
Comment 3 Olivier Thomann CLA 2009-05-11 18:04:40 EDT
(In reply to comment #2)
> Is that case also covered by #255452?
Now this is bug 263877 that has been fixed post 3.4.2.
The fix is available in the 3.5 stream since 3.5M6.
Comment 4 Daniel CLA 2009-05-11 18:07:55 EDT
According to the last comment in #263877, there should be a patch for the 3.4 stream for this issue.  When will that be available through the "Search for Updates" feature?
Comment 5 Olivier Thomann CLA 2009-05-11 18:56:17 EDT
No, there is a jar that provides this fix available on the JDT/Core update page.
See http://www.eclipse.org/jdt/core/r3.4/index.php#UPDATES.
This has to be applied through a feature patch or via an update site.
There is no "official" Eclipse build post 3.4.2.

I'll see if I can setup an update site on the JDT/Core page that would provide this update.
Comment 6 Daniel CLA 2009-05-12 10:30:01 EDT
The patch doesn't work.  The versions dialog lists the version for org.eclipse.jdt.core as 3.4.5.v_895_R34x, but I still get the same compiler errors.

What's the correct way to install this patch?
Comment 7 Daniel CLA 2009-05-12 10:34:03 EDT
I'm also compiling using compatibility level 1.6, and bug #263877 was marked as [1.5].  Was it also fixed for the 1.6 compiler?
Comment 8 Olivier Thomann CLA 2009-05-12 11:02:48 EDT
Yes, this is fixed for any compliance level >= 1.5.
I'll send you a patch and you'll tell me if it works for you.
Comment 9 Frederic Fusier CLA 2009-05-15 04:50:09 EDT
As the comment 0 does not compile in Eclipse 3.4.2, this bug is rather a duplicate of bug 263877 rather than bug 255452. Hence, change the target accordingly...

*** This bug has been marked as a duplicate of bug 263877 ***
Comment 10 Frederic Fusier CLA 2009-05-15 04:51:29 EDT
Verified using build I20090313-0100 (aka 3.5M6)