[Issue 12652] New: Non-constant hash initializers should have a special-case diagnostic

via Digitalmars-d-bugs digitalmars-d-bugs at puremagic.com
Sat Apr 26 03:48:52 PDT 2014


https://issues.dlang.org/show_bug.cgi?id=12652

          Issue ID: 12652
           Summary: Non-constant hash initializers should have a
                    special-case diagnostic
           Product: D
           Version: D2
          Hardware: All
                OS: All
            Status: NEW
          Keywords: diagnostic
          Severity: enhancement
          Priority: P1
         Component: DMD
          Assignee: nobody at puremagic.com
          Reporter: andrej.mitrovich at gmail.com

-----
int[int] x = [1:1];

void main() { }
-----

test.d(2): Error: non-constant expression [1:1]

Associative arrays are supposed to be a first-class feature of D, but until we
make them CTFE-able we should emit better diagnostics (essentially do some
special-cases when hashes are involved).

The above code is something newcomers to D very frequently run into, and the
diagnostic doesn't really tell them what's wrong. Some suggestions:

-----
Error: Associative array literals currently cannot be used to initialize
globals. Try using a module constructor instead.
-----

This will at least point them to a workaround. Maybe a link to a page with a
workaround would be nice too.

--


More information about the Digitalmars-d-bugs mailing list