drepl icon indicating copy to clipboard operation
drepl copied to clipboard

Allow non-constant variable initializers

Open MartinNowak opened this issue 11 years ago • 2 comments

At module scope variable declarations only have constant initializers. To support auto seed = unpredictableSeed() the corresponding module should be rewritten like so.

module _mod2;
import _mod0, _mod1;

typeof(unpredictableSeed()) seed;

shared static this()
{
    seed = unpredictableSeed();
}

MartinNowak avatar Feb 12 '14 18:02 MartinNowak

I had some issue with this in dabble, i.e.:

input: auto a = appender!string;
re-write: typeof(appender!string) a; // error: expression (appender!string) has no type

I ended up using lambdas to deduce the type:

typeof( (()=>(appender!string))() )

callumenator avatar Feb 17 '14 00:02 callumenator

Thanks, good to know. I thought that remaining property differences for typeof were already fixed, but they aren't.

MartinNowak avatar Feb 17 '14 03:02 MartinNowak