www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - Check for duplicated AA keys at compile time

reply Jacob Carlborg <doob me.com> writes:
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];

-- 
/Jacob Carlborg
Jun 03 2017
next sibling parent Stefan Koch <uplink.coder googlemail.com> writes:
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];
You can write one yourself as soon as newCTFE supports it :)
Jun 03 2017
prev sibling parent Nick Treleaven <nick geany.org> writes:
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'
Jun 11 2017