Type inference in array literals

Max Samukha spambox at d-coding.com
Sat Aug 28 11:00:19 PDT 2010

On 08/28/2010 07:19 PM, Jesse Phillips wrote:
> D uses the last element in the array literal to select the type. I think there was a discussion on why a common type wasn't used, but don't remember the conclusion. It would be nice if it used the item you are assigning to and check they can convert to it.

According to TDPL (page 40), common type should be used:

"The element type of the array is determined by agreement among all 
elements of the
array, which is computed by means of the conditional operator ? : 
(anticipating § 2.3.16)."

More information about the Digitalmars-d mailing list