Only const or immutable class thread local variables are allowed

Jonathan M Davis jmdavisProg at gmx.com
Tue Dec 10 00:27:46 PST 2013


On Tuesday, December 10, 2013 09:13:12 Joseph Rushton Wakeling wrote:
> On 10/12/13 08:44, Jonathan M Davis wrote:
> > It's a matter of what you can directly initialize a non-local variable
> > with. Module-level variables, static variables, and member variables all
> > have to be known at compile time, and you can't have a mutable class
> > instance being constructed at compile time and then kept around until
> > runtime.
> 
> That's obvious in retrospect but not on the basis of the error message:
> 
>      Error: variable std.random2.generator.rndGen.result is mutable. Only
> const or immutable class thread local variable are allowed, not
> std.random2.generator.MersenneTwisterEngine!(uint, 32, 624, 397, 31,
> 2567483615u, 11, 4294967295u, 7, 2636928640u, 15, 4022730752u, 18,
> 1812433253u).MersenneTwisterEngine

A lot of dmd's error messages aren't great.

> Would this be better?
> 
>      Cannot initialize thread-local class variable %s with a mutable value. 
> Only const or immutable initial values are allowed (e.g. null).

That would be better.

- Jonathan M Davis


More information about the Digitalmars-d-learn mailing list