Bug 35438 - CastExpression resolution departs from JLS section 6.5.1
Summary: CastExpression resolution departs from JLS section 6.5.1
Status: VERIFIED FIXED
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Core (show other bugs)
Version: 2.1   Edit
Hardware: PC Linux
: P3 normal with 1 vote (vote)
Target Milestone: 2.1.1   Edit
Assignee: Philipe Mulet CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2003-03-20 23:28 EST by Chapman Flack CLA
Modified: 2003-06-06 12:47 EDT (History)
1 user (show)

See Also:


Attachments
patch for BlockScope (1.67 KB, patch)
2003-03-21 07:58 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 Chapman Flack CLA 2003-03-20 23:28:21 EST
2.1.0-RC3 200303192032; problem persists from earlier builds.

public class Flitsch {

    public static float BRATSCH = 42;
    public static class BRATSCH {
    }
    
    public Object o;
    
    public void sozzle() {
        Flitsch.BRATSCH = 43;
        Flitsch.BRATSCH b = (Flitsch.BRATSCH)o;
    }
}

In this code, the cast will be squiggled with the message "Flitsch.BRATSCH
cannot be resolved." None of the other occurrences of Flitsch.BRATSCH will be
squiggled, so the compiler is able to disambiguate the type from the field in
other contexts, but not in a CastExpression. javac accepts the code.

JLS section 6.5.1 provides: A name is syntactically classified as a TypeName in
these contexts:
...
As the type mentioned in the cast operator of a cast expression (15.16)
...

Interestingly, if the unqualified typename is used in the cast, Flitsch.BRATSCH
b = (BRATSCH)o, it is accepted. Only the qualified form gives trouble.
Comment 1 Philipe Mulet CLA 2003-03-21 04:34:36 EST
Reproduced. Indeed, this is a bug.
Comment 2 Philipe Mulet CLA 2003-03-21 07:58:45 EST
Created attachment 4278 [details]
patch for BlockScope
Comment 3 Philipe Mulet CLA 2003-03-21 07:59:19 EST
Kent - pls verify patch
Comment 4 Philipe Mulet CLA 2003-03-21 09:09:31 EST
In this particular case, a workaround is to not qualify, however in general, 
when accessing from some external code, this isn't possible.

However, this isn't a new bug.
Comment 5 Philipe Mulet CLA 2003-03-21 09:09:58 EST
Not critical for 2.1
Comment 6 Chapman Flack CLA 2003-03-21 10:37:07 EST
Thanks for the quick patch! I'll give it a try.

I'm not sure I understand the last couple of comments. If this is not a new bug,
is it an old bug?  I did search first, but I didn't find it. Sorry if I missed it.

As you point out, the workaround of using an unqualified name is not feasible in
the general case.  Also, as you would guess, the problem is most likely to be
apparent in generated code, where the member names are constrained by some
external design requirement; otherwise one would just use different names and
never see the problem.

That means in the practical situations where this bug is likely to bite, there
may be no really practical workaround--one that doesn't require redesign of a
code generator and a number of related components.
Comment 7 Philipe Mulet CLA 2003-03-21 10:53:49 EST
By old bug, I meant it isn't a recent regression but rather a long standing bug.
I agree this isn't trivial to workaround, but since we are in strict release 
mode (see Eclipse end game plan), only stop ship bugs are to be addressed at 
this stage.

Such a collision scenario isn't very frequent to make it critical (we had it 
wrong in 2.0 as well, and nobody noticed until today).
Comment 8 Kent Johnson CLA 2003-03-21 13:56:40 EST
Patch looks good.
Comment 9 Philipe Mulet CLA 2003-03-27 05:05:50 EST
Defer
Comment 10 Philipe Mulet CLA 2003-04-01 05:04:36 EST
Reopening
Comment 11 Philipe Mulet CLA 2003-04-01 05:07:31 EST
Fixed
Comment 12 Philipe Mulet CLA 2003-04-08 07:28:55 EDT
Backported to 2.1 maintenance stream.
Comment 13 Jerome Lanneluc CLA 2003-04-15 10:46:17 EDT
Fixed in 2.2 stream as well.
Comment 14 David Audel CLA 2003-06-02 06:56:08 EDT
Verified.
Comment 15 David Audel CLA 2003-06-06 12:47:39 EDT
Verified in 3.0M1