www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 13999] New: Associative array literal with static array keys

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

          Issue ID: 13999
           Summary: Associative array literal with static array keys must
                    now have matching key lengths
           Product: D
           Version: D2
          Hardware: All
                OS: All
            Status: NEW
          Severity: regression
          Priority: P1
         Component: DMD
          Assignee: nobody puremagic.com
          Reporter: jakobovrum gmail.com

---
void main()
{
    string[immutable(dchar[2])] aa = ["ああ": "foo", "あ": "bar"];
}
---
test.d(3): Error: cannot implicitly convert expression
(["\xe3\x81\x82\xe3\x81\x82":"foo", "\xe3\x81\x82":"bar"]) of type
string[string] to string[immutable(dch
ar[2])]
---

Using DMD 2.067/master at the time of posting.

This used to compile, for better or worse. Changing the second entry's key to
two code points, like "ああ", makes it compile. Not sure if this is now a DMD
or
druntime issue, or both.

Although tangential, the error can be really hard to find in big literals.

--
Jan 17 2015