www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 17607] New: not an associative array initializer

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

          Issue ID: 17607
           Summary: not an associative array initializer
           Product: D
           Version: D2
          Hardware: All
                OS: All
            Status: NEW
          Severity: enhancement
          Priority: P1
         Component: dmd
          Assignee: nobody puremagic.com
          Reporter: andre s-e-a-p.de

I build an AWS SDK for D based on the AWS definitions. I generate structures
for the input/output data. These structures I fill with the structure
initializer which works quite fine for anything except associate arrays.

This is the minimized structure to create an record in an AWS Dynamo DB table.
For the record you specify the attribute values via an associative array. (I
generate an associative array as in the AWS API definition an JSON Object is
used).

Although structure initializer works quite well for array, it does not work for
associative arrays.
test.d(19): Error: not an associative array initializer

The coding below does not compile. Instead I have to write much more verbose
coding to fill the item.

Indepent of the current ongoing DIP, is there any chance to enable structure
initializer for associative arrrays?

struct PutItemRequest
{
    string tableName;
    AttributeValue[string] item;
}

struct AttributeValue
{
    bool BOOL;
    string S;
    AttributeValue[string] M;
    string[] SS;
}

void main()
{
    PutItemRequest request = {
        tableName: "table1",
        item: [
            "field1": {S: "LALA"},
            "field2": {SS: ["A", "B", "C"]},
            "field3": {
                M: ["fieldA": {S: "234"}]
            }
        ]
    };
}

--
Jul 05