Community
Participate
Working Groups
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.
We shouldn't try dealing with the second case until bug 352370 is done. It's the enhancement to support the number type.
*** Bug 356527 has been marked as a duplicate of this bug. ***
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!
Closing.