Summary: Ambiguously designed array syntax
           Product: D
           Version: D2
          Platform: All
        OS/Version: All
            Status: NEW
          Severity: normal
          Priority: P2
         Component: DMD

--- Comment #0 from 2010-08-21 10:24:52 PDT ---
This is a wrong program, where's the bug?

import std.stdio: writeln;
void main() {
    int[] dict = [1:2, 3:4, 5:6];

The output is:
[0, 2, 0, 4, 0, 6]

The problem is that the literal of 'aa' is both a valid dynamic array literal
and valid associative array literal. On default DMD chooses to see it as an
associative array, but this choice is arbitrary:

import std.stdio: writeln;
void main() {
    auto aa = [1:2, 3:4, 5:6];

It's very bad to have ambiguous built-in collection literals, it's a source of
many problems.

And it's not even an uniform choice, with dmd 2.048 this program:

void foo(int[] a) {}
void bar(int[int] aa) {}
void main() {
    foo([1:2, 3:4, 5:6]);
    bar([1:2, 3:4, 5:6]);

Produces the errors:
test.d(4): Error: function (int[] a) is not callable using argument
types (int[int])
test.d(4): Error: cannot implicitly convert expression ([1:2,3:4,5:6]) of type
int[int] to int[]

Configure issuemail:
------- You are receiving this mail because: -------

Reply via email to