Bug 106870

Summary: [1.5][compiler] Should autoboxing handle this equal expression?
Product: [Eclipse Project] JDT Reporter: Olivier Thomann <Olivier_Thomann>
Component: CoreAssignee: Philipe Mulet <philippe_mulet>
Status: RESOLVED INVALID QA Contact:
Severity: normal    
Priority: P3    
Version: 3.2   
Target Milestone: 3.2 M3   
Hardware: PC   
OS: Windows XP   
Whiteboard:

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