Thread overview
[Issue 17607] not an associative array initializer
Oct 30, 2017
John Colvin
Oct 31, 2017
Andre
Oct 31, 2017
John Colvin
Nov 01, 2017
Andre
Apr 02, 2018
Seb
Apr 09, 2018
Andre
Dec 17, 2022
Iain Buclaw
October 30, 2017
https://issues.dlang.org/show_bug.cgi?id=17607

John Colvin <john.loughran.colvin@gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |john.loughran.colvin@gmail.
                   |                            |com

--- Comment #1 from John Colvin <john.loughran.colvin@gmail.com> ---
Another simpler case of this:

struct S
{
    //Error: not an associative array initializer
    D a = ["fdsa": ["fdsafd": "fdsfa"]];

    // OK
    D b = (["fdsa": ["fdsafd": "fdsfa"]]);
}

struct D
{
    this(string[string][string]) {}
}


Andre, perhaps putting brackets around it is a workaround for you as well?

--
October 31, 2017
https://issues.dlang.org/show_bug.cgi?id=17607

--- Comment #2 from Andre <andre@s-e-a-p.de> ---
(In reply to John Colvin from comment #1)
> Another simpler case of this:
> 
> struct S
> {
>     //Error: not an associative array initializer
>     D a = ["fdsa": ["fdsafd": "fdsfa"]];
> 
>     // OK
>     D b = (["fdsa": ["fdsafd": "fdsfa"]]);
> }
> 
> struct D
> {
>     this(string[string][string]) {}
> }
> 
> 
> Andre, perhaps putting brackets around it is a workaround for you as well?

thanks for the workaround. The Amazon Web Service request structures are quite
complex. They have multiple fields with multiple hierarchies. Every additional
characters makes it more difficult to read for other developers using the AWS
library.
If the syntax could be enhanced, this would really great.

--
October 31, 2017
https://issues.dlang.org/show_bug.cgi?id=17607

--- Comment #3 from John Colvin <john.loughran.colvin@gmail.com> ---
My use case involves structures with these initialisers being used by people who aren't really D programmers, so it looks bad and is confusing to have the extra `( ... )` for me too.

Hopefully there is a solution. I don't think it's a case of needing improved syntax in the language, it's just a compiler bug.

--
November 01, 2017
https://issues.dlang.org/show_bug.cgi?id=17607

Andre <andre@s-e-a-p.de> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Severity|enhancement                 |normal

--
April 02, 2018
https://issues.dlang.org/show_bug.cgi?id=17607

Seb <greensunny12@gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |greensunny12@gmail.com

--- Comment #4 from Seb <greensunny12@gmail.com> ---
FYI: while it doesn't fix this bug, this PR is still very related this this enhancement request:

https://github.com/dlang/dmd/pull/8051

--
April 09, 2018
https://issues.dlang.org/show_bug.cgi?id=17607

--- Comment #5 from Andre <andre@s-e-a-p.de> ---
(In reply to John Colvin from comment #3)
> My use case involves structures with these initialisers being used by people who aren't really D programmers, so it looks bad and is confusing to have the extra `( ... )` for me too.
> 
> Hopefully there is a solution. I don't think it's a case of needing improved syntax in the language, it's just a compiler bug.

I just have another look. The workaround is unfortunately not working but causing a lot of errors:

struct PutItemRequest
{
    AttributeValue[string] item;
}

struct AttributeValue
{
    string S;
}

void main()
{
    PutItemRequest request = {
                item: ([
                    "field1": {S: "LALA"}
                ])
        };
}

test2.d(15): Error: found } when expecting ; following statement
test2.d(16): Error: found ] instead of statement
test2.d(17): Error: found ; when expecting ,
test2.d(18): Error: expression expected, not }
test2.d(18): Error: key:value expected for associative array literal
test2.d(18): Error: found EOF when expecting ,
test2.d(14): Error: found EOF when expecting ]
test2.d(14): Error: found EOF when expecting )
test2.d(18): Error: found end of file instead of initializer
test2.d(18): Error: semicolon expected, not EOF
test2.d(18): Error: found EOF when expecting } following compound statement

--
December 02, 2022
https://issues.dlang.org/show_bug.cgi?id=17607

Steven Schveighoffer <schveiguy@gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |schveiguy@gmail.com

--- Comment #6 from Steven Schveighoffer <schveiguy@gmail.com> ---
Just ran into this. Note the problem has nothing to do with structs:


```d
int[char][char] arr =  ['A' : ['B': 0]] ; // error
int[char][char] arr = (['A' : ['B': 0]]); // ok
```

Does anyone have an actual explanation of why this is happening? It looks like an AA initializer to me.

--
December 03, 2022
https://issues.dlang.org/show_bug.cgi?id=17607

--- Comment #7 from Steven Schveighoffer <schveiguy@gmail.com> ---
This is most definitely a bug:

```d
// int[char][char] arr = ['A' : ['B': 0]]; // error
              auto arr = ['A' : ['B': 0]]; // ok
pragma(msg, typeof(arr)); // int[char][char]
```

--
December 17, 2022
https://issues.dlang.org/show_bug.cgi?id=17607

Iain Buclaw <ibuclaw@gdcproject.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Priority|P1                          |P3

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

--- Comment #8 from dlangBugzillaToGithub <robert.schadek@posteo.de> ---
THIS ISSUE HAS BEEN MOVED TO GITHUB

https://github.com/dlang/dmd/issues/17804

DO NOT COMMENT HERE ANYMORE, NOBODY WILL SEE IT, THIS ISSUE HAS BEEN MOVED TO GITHUB

--