Community
Participate
Working Groups
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(...).
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.
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.
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.
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
Verified in I20050214