Struct literals and AA literals

Lodovico Giaretta via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Mon May 23 12:51:18 PDT 2016


Hi,

Today I stumbled upon this weird error:

     struct ConfigContainer
     {
         Config[string] configs;
     }

     struct Config
     {
         string foo;
         string bar;
     }

     enum ConfigContainer cc = {
         configs: [            // error: not an associative array 
initializer
             "MyConfig": {
                 foo: "foo",
                 bar: "bar"
             }
         ]
     };

But this other way works fine:

     enum ConfigContainer cc = {
         configs: [
             "MyConfig": Config("foo", "bar")
         ]
     };

Is this a bug? Or is this by design?

Thank you in advance.

Lodovico Giaretta


More information about the Digitalmars-d-learn mailing list