Type mismatch error problem with Double arrays - why?

Why would this raise a TypeMismatch exception:

Dim Masses() As Double = Array(42, 42, 50, 42, 33, 125, 48, 36, 42, 42)

The numbers are perfectly fine Doubles - and yes, I know I can force Xojo by writing

Dim Masses() As Double = Array(42.0, 42, 50, 42, 33, 125, 48, 36, 42, 42)

but I’m specifying what they should be, and there should be no problem in treating them as Doubles just because they happen to be “round numbers” (the numbers will come as a string from a database and are not usually round, but they could be and happen to be for this particular data set).

Obviously the Array function does not use hints from the assignment to properly set its return type - it only evaluates the given parameters and uses the lowest common data type that works.

But it’s also interesting (or concerning) that Xojo doesn’t auto-convert in this case. Probably because it’s an array which makes it more complicated.

I’m confused by your usage case here…

If the numbers are coming in as a string you have to convert them and put them in a typed variable as a specific number type before you can do that… unless you are writing code that writes code… but then you could do Format(Val(strNum), FormatTo use) to write the numbers on the line of code…

But I agree that the compiler should be smart enough to look at the type on the left side of the equal sign… But that change would likely take a compiler engineer…