Currently the documentation states that the type for the raw array literal is derived from the first element in the literal:
A better rule will be to use the 'most derived type' - the type to which all the other types can be implicitly converted to. In no such type exists in the literal, it probably should be an error.
For example: [1, 2, 3.0] should be a raw array of Double (assuming that the "1" and "2" literals are 32-bit integers).
Similarly, having classes "Foo" and "Bar extends Foo", [Foo new(), Bar new()] should be a raw array of Foo.
Maybe the Type getScore(Type) function could be used for such a purpose. Try type1 getScore(type2) vs type2 getScore(type1), whoever wins gets to be the array's innerType. If the score is negative (except -1, which means something has to be resolved first), throw an error that there are incompatible types in the array literal.
This way of handling it makes the most sense, +1
(aka a bump after a year and a month, while poking around bugs at 2am because I thought I found a problem but did not)
WITH THAT, I GO TO BED. Hopefully.
Ok, I may take a whack at this sometime. No promises, though. :P
BUMP. Hi @shamanas.
Merge pull request #610 from shamanas/master
Use findCommonRoot to infer the type of an array literal. Closes the oldest issue standing, #10
Closed by 536f51c :D