Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.

Bug 355014

Summary: various problems with array literals
Product: z_Archived Reporter: Matt Heitz <mheitz>
Component: EDTAssignee: Project Inbox <edt.javagen-inbox>
Status: CLOSED INVALID QA Contact:
Severity: normal    
Priority: P3 CC: broy2
Version: unspecified   
Target Milestone: ---   
Hardware: PC   
OS: Windows XP   
Whiteboard:

Description Matt Heitz CLA 2011-08-17 17:25:40 EDT
If you like ClassCastExceptions, try running the code we generate from these lines

  x1 int[] = [1, 2, 3];
  x2 int[] = [1, 2, 178793];

In the first case, the literal is an array of smallints, and the exception happens because you can't normally assign an array of one type to an array of another type.  One possible fix might be to generate the elements of the literal based on the type of the assignment's LHS.

The second case fails because the array's type is array of number (the elements are smallint and int, and number is the superclass of both).  I don't know if that's a mistake...maybe it should be an array of ints instead (in other words, follow the usual type promotion rules).  If it's not a mistake, then we need to generate the code differently because we're just boxing each element, not making a number from it.
Comment 1 Matt Heitz CLA 2011-08-17 17:28:22 EDT
We shouldn't try dealing with the second case until bug 352370 is done.  It's the enhancement to support the number type.
Comment 2 Matt Heitz CLA 2011-09-06 13:49:57 EDT
*** Bug 356527 has been marked as a duplicate of this bug. ***
Comment 3 Matt Heitz CLA 2011-09-15 12:06:27 EDT
Due to the recent set of language changes, "x1 int[] = [1, 2, 3];" is no longer valid.  It's an assignment of a smallint array to an int array, and they're not compatible types.

The second example is invalid for the same reason.  And, the type of the array literal [1, 2, 178793] is correct: it's supposed to be number not int.  If we used type conversions to dictate the array's type, [ 3, "hello" ] would be an array of strings!
Comment 4 Matt Heitz CLA 2011-09-15 12:06:34 EDT
Closing.