Check for duplicated AA keys at compile time

Nick Treleaven via Digitalmars-d digitalmars-d at puremagic.com
Sun Jun 11 04:22:55 PDT 2017


On Saturday, 3 June 2017 at 14:59:38 UTC, Jacob Carlborg wrote:
> Would it be reasonable for the compiler to check for duplicated 
> keys in an associative array literal where all the keys are 
> known at compile time? For example:
>
> auto aa = ["foo": 1, "foo": 1];

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

Same goes for array literals with duplicate indexed initializers 
(from BZ link):

int[] a = [0:10, 0:20]; //allowed

Although for struct named member init dmd warns:

struct S {
     int  a;
}

S s = { a: 2, a: -5 }; //Error: duplicate initializer for field 
'a'


More information about the Digitalmars-d mailing list