[Issue 18945] immutable variable is used as if it's an enum

d-bugmail at puremagic.com d-bugmail at puremagic.com
Tue Jun 5 15:34:46 UTC 2018


https://issues.dlang.org/show_bug.cgi?id=18945

--- Comment #7 from David Bennett <davidbennett at bravevision.com> ---
(In reply to Jonathan M Davis from comment #6)
> 
> Just use an enum if you want the value to be known and used at compile time,
> and use an immutable variable if you want it to be known and used at
> runtime. Don't try to have a variable with different values at compile time
> and runtime. And if for some reason, you want the value calculated at
> compile time but to still have a variable, then use an enum to initialize
> the immutable variable. That's what you have to do with mutable variables
> already.

So the deprecation message shouldn't have a concrete example to opt-in to keep
the current functionality.
Just something like "Deprecation: Using an immutable variable at compile time
will be removed in a future version. Try changing `n` in `int[n] a;` to use an
enum variable.".
And assume D users will know that they will need to implement the enum
separately from the immutable if they want to keep the status quo?

Then there are immutable struct members used at compile time, they might not be
easy to convert to an enum.
https://run.dlang.io/is/cfGfxw
I've never seen it used like that... but it does work currently.

--


More information about the Digitalmars-d-bugs mailing list