Bug 156108 - [1.5][compiler] Autoboxing doesnt workt in switch-statement
Summary: [1.5][compiler] Autoboxing doesnt workt in switch-statement
Status: VERIFIED FIXED
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Core (show other bugs)
Version: 3.2   Edit
Hardware: PC Linux
: P3 normal (vote)
Target Milestone: 3.2.1   Edit
Assignee: Philipe Mulet CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2006-09-04 07:52 EDT by Jörg Schuberth CLA
Modified: 2006-09-18 12:47 EDT (History)
0 users

See Also:


Attachments
Proposed patch (6.22 KB, patch)
2006-09-04 11:10 EDT, Philipe Mulet CLA
no flags Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Jörg Schuberth CLA 2006-09-04 07:52:41 EDT
/* autoboxing in switch statement */
Byte no = 127; //warning: int boxed to Byte > fine
switch(no) { //warning: Byte is unboxed into int > why in int??? output right?
case -128: //error: cannot convert int to Byte > needs a explicit (byte)cast. 
    break;
  case (byte)127: //works
    break;
}
no = new Byte(127) //also doesnt work without cast in jdt-compiler

/* sun compiler doesnt need the explicit casts as it should be */
Comment 1 Philipe Mulet CLA 2006-09-04 10:10:08 EDT
The second error in "new Byte(127)" is legite; there is no narrowing conversion on message invocations (dixit JLS 5.3)
Comment 2 Philipe Mulet CLA 2006-09-04 10:44:21 EDT
There are indeed a few places where we do not allowing narrowing conversion before boxing (int (byte) cst assignmt compatible with Byte JLS5.2)

Same issue for the following code which should be accepted.
public class X {
	Byte foo() {
		final int i = -128;
		return i;
	}
}
Comment 3 Philipe Mulet CLA 2006-09-04 10:51:11 EDT
Added AutoboxingTest#test121-122.
Comment 4 Philipe Mulet CLA 2006-09-04 11:00:58 EDT
Also there are autoboxing warnings emitted for case statement which aren't appropriate, since in the end no such conversion is performed.

Should get rid of following line which is unnecessary in CaseStatement#resolveCase
  constantExpression.computeConversion(scope, caseType, switchExpressionType);

Comment 5 Philipe Mulet CLA 2006-09-04 11:10:28 EDT
Created attachment 49349 [details]
Proposed patch

patch for 3.2 maintenance
Comment 6 Philipe Mulet CLA 2006-09-04 12:21:50 EDT
Released for 3.2.1 [R3_2_maintenance]
Released for 3.3M2 [HEAD]

Fixed
Comment 7 David Audel CLA 2006-09-12 04:08:45 EDT
Verified for 3.2.1 using build M20060908-1655
Comment 8 Frederic Fusier CLA 2006-09-18 12:47:53 EDT
Verified for 3.3 M2 using build I20060918-0010.