Problem with circular imports of modules with static ctors an immutable variables

Uranuz via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Thu Apr 14 22:35:24 PDT 2016


In my program I have error with circular imports of modules with 
static ctors. So I decided to move ctors in separate file and 
import it only from the 1st file. But problem is that in the 
first file I have immutables that should be initialized in shared 
static ctor. However doing it from another module's ctor gives 
compilation error: "Error: cannot modify immutable expression".
1. Is it a bug?
2. Could I solve this problem another way?

Example code:

module mod;

import mod_init;

static immutable string[string] aa;

...

--------------
module mod_init;

import mod;

shared static this
{
    aa = [ "a": "b", "c": "d" ]; //This gives compilation error
}

...


More information about the Digitalmars-d-learn mailing list