Bug 106870 - [1.5][compiler] Should autoboxing handle this equal expression?
Summary: [1.5][compiler] Should autoboxing handle this equal expression?
Status: RESOLVED INVALID
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Core (show other bugs)
Version: 3.2   Edit
Hardware: PC Windows XP
: P3 normal (vote)
Target Milestone: 3.2 M3   Edit
Assignee: Philipe Mulet CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2005-08-12 12:08 EDT by Olivier Thomann CLA
Modified: 2005-10-18 06:32 EDT (History)
0 users

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Olivier Thomann CLA 2005-08-12 12:08:30 EDT
Using 3.2M1,

class X {
    boolean foo(Long l, Float f) {
	return f == l;
    }
}

We report:----------
1. ERROR in d:\tests_sources\X.java
 (at line 3)
	return f == l;
	       ^^^^^^
Incompatible operand types Float and Long
----------
1 problem (1 error)

JLS3 states:
The equality operators may be used to compare two operands that are convertible
(ยง5.1.8) to numeric type, or two operands of type boolean or Boolean, or
two operands that are each of either reference type or the null type.

I am not sure if this should handle this case.

Since this is fine:
class X {
    boolean foo(long l, float f) {
	return f == l;
    }
}
I would expect the first one to also be fine.
Comment 1 Philipe Mulet CLA 2005-10-18 06:32:15 EDT
Comparison operators only perform boxing if exactly one operand type is primitive.
However, other operations are more tolerant:

public class X {
    float bar(Long l, Float f) {
    	return this == null ? f : l;  // both are unboxed to float
    }
}

Added AutoboxingTest#test116