Bug 84345 - [1.5][compiler] Widening reference is possible when boxing in a cast expression
Summary: [1.5][compiler] Widening reference is possible when boxing in a cast expression
Status: VERIFIED FIXED
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Core (show other bugs)
Version: 3.1   Edit
Hardware: PC Windows XP
: P3 normal (vote)
Target Milestone: 3.1 M5   Edit
Assignee: Philipe Mulet CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2005-02-03 11:57 EST by Olivier Thomann CLA
Modified: 2005-02-15 09:00 EST (History)
0 users

See Also:


Attachments
Apply on HEAD (821 bytes, patch)
2005-02-03 11:59 EST, Olivier Thomann CLA
no flags Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Olivier Thomann CLA 2005-02-03 11:57:29 EST
In a cast expression, it is possible to cast a byte into Number.
byte b = 0;
Number n = (Number) b;

is legal. Right now we report an incompatible cast.

The test in Expression checks for == in case of boxing instead of
isCompatibleWith(...).
Comment 1 Olivier Thomann CLA 2005-02-03 11:59:01 EST
Created attachment 17659 [details]
Apply on HEAD

I am running all the tests now.
With this patch, we report the cast as unnecessary. Indeed, if you remove the
cast, it compiles perfectly fine.
Comment 2 Olivier Thomann CLA 2005-02-03 13:01:42 EST
With this patch, everything looks good for the cast expression, but there is a
side effect in the EqualExpression.
The following code doesn't report an error anymore:

public class X {
  public Object foo() {
    java.io.Serializable o = null;
    if (o == 0) return o;
    return this;
  }
}

The JLS3 don't require the types to be cast compatible anymore. They refer to
types that need to be convertible to numeric types. java.io.Serializable is not
convertible to a numeric types.
Check 5.1.8 section.
Comment 3 Olivier Thomann CLA 2005-02-03 14:28:43 EST
Forget what I said in comment 2. This was wrong. In case of reference type, the
casting conversion still apply. I need to investigate what should be the fix in
the cast check to handle the equality expressions.
Comment 4 Philipe Mulet CLA 2005-02-07 12:34:23 EST
I believe the spec is a bit unprecise. It does perform numeric comparison as
soon as any of the operand is a numeric type.
Adjusted the implementation along this idea.

Added AutoboxingTest#test089.
Fixed
Comment 5 Jerome Lanneluc CLA 2005-02-15 09:00:42 EST
Verified in I20050214