Bug 80455

Summary: [5.0] ITypeBinding.canAssign not aware of type boxing
Product: [Eclipse Project] JDT Reporter: Martin Aeschlimann <martinae>
Component: CoreAssignee: Jerome Lanneluc <jerome_lanneluc>
Status: VERIFIED FIXED QA Contact:
Severity: normal    
Priority: P3 CC: markus.kell.r
Version: 3.0   
Target Milestone: 3.1 M4   
Hardware: PC   
OS: Windows XP   
Whiteboard:

Description Martin Aeschlimann CLA 2004-12-08 06:27:25 EST
20041208

With the latest changes for type boxing (in N20041207) our tests for the assign
compatibility fail:

boolean b= true;
Object o;

o= b;  // valid code, no compiler error
but typeBindingOfB.isAssignCompatible(typeBindingOfO) is false
Comment 1 Philipe Mulet CLA 2004-12-08 09:32:29 EST
Autoboxing support is being added gradually.
Comment 2 Jerome Lanneluc CLA 2004-12-09 06:21:22 EST
Changed TypeBinding#isAssignmentCompatible(...) to check also if the argument is
boxing compatible with the receiver.
Added regression test CompatibilityRuleTests#test023().
Comment 3 Frederic Fusier CLA 2004-12-15 07:53:05 EST
Verified for 3.1 M4 using build I200412142000.
Comment 4 Frederic Fusier CLA 2004-12-15 07:56:29 EST
To verify it I've used ASTView 1.0.2 + following code:
package b80455;
public class Test {
	void foo() {
		Integer itg = new Integer(0);
		int ibt = 0;
		if (itg == ibt)
			System.out.println("equals");
	}
}
+
breakpoint in ASTViewLabelProvider.getText(Object obj)
  condition: ((ASTNode)obj).getNodeType() == ASTNode.IF_STATEMENT
+
code snippet in Debugger Display view:
org.eclipse.jdt.core.dom.IfStatement ifStatement =
(org.eclipse.jdt.core.dom.IfStatement) obj;
org.eclipse.jdt.core.dom.InfixExpression expression =
(org.eclipse.jdt.core.dom.InfixExpression) ifStatement.getExpression();
org.eclipse.jdt.core.dom.ITypeBinding leftBinding =
expression.getLeftOperand().resolveTypeBinding();
org.eclipse.jdt.core.dom.ITypeBinding rightBinding =
expression.getRightOperand().resolveTypeBinding();
rightBinding.isAssignmentCompatible(leftBinding);
Comment 5 Frederic Fusier CLA 2004-12-15 09:22:09 EST
Test can easilier be done using new feature of ASTView to compare bindings:
 - Select a binding and choose 'add to comparison tree' in the context menu
 - Then select the other binding you want to compare with the first one,
 - In the comparison tray you can see the result of the test

Thanks Martin for the tip :-)