Associative array literal. Why doesn't it compile?

2015-08-14 Thread Adel Mamin via Digitalmars-d-learn
Compiler dmd_2.068.0-0_amd64.deb on Ubuntu 12.04 Linux: auto lookup = [ one:1, two:2 ]; The dmd error: Error: non-constant expression [one:1, two:2] Why doesn't it compile? As a workaround I could do the assignment one element at a time in a loop. It would be uglier though.

Re: Associative array literal. Why doesn't it compile?

2015-08-14 Thread Ali Çehreli via Digitalmars-d-learn
On 08/13/2015 11:48 PM, Adel Mamin wrote: Compiler dmd_2.068.0-0_amd64.deb on Ubuntu 12.04 Linux: auto lookup = [ one:1, two:2 ]; The dmd error: Error: non-constant expression [one:1, two:2] I think the problem is when the variable is defined at module scope. It works inside functions, etc.

Re: Associative array literal. Why doesn't it compile?

2015-08-14 Thread BBasile via Digitalmars-d-learn
On Friday, 14 August 2015 at 06:48:27 UTC, Adel Mamin wrote: Compiler dmd_2.068.0-0_amd64.deb on Ubuntu 12.04 Linux: auto lookup = [ one:1, two:2 ]; The dmd error: Error: non-constant expression [one:1, two:2] Why doesn't it compile? As a workaround I could do the assignment one element at a

Re: Associative array literal. Why doesn't it compile?

2015-08-14 Thread anonymous via Digitalmars-d-learn
On Friday, 14 August 2015 at 07:04:53 UTC, BBasile wrote: It's because of the key type (string is a library type). This is not true. It's not because of the key type. And string is not a library type.

Re: Associative array literal. Why doesn't it compile?

2015-08-14 Thread Temtaime via Digitalmars-d-learn
It's because it's implemented in DMD only partly. There's a bug report associated with it.