www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - Wrong initialization of variables

reply Andrey <saasecondbox yandex.ru> writes:
Hello,
Simple code:
 import std.stdio;
 
 mixin template DeclFlag(alias values)
 {
     static foreach(value; values)
     {
         mixin("bool has" ~ value ~ " = false;");
     }
 }
 
 enum Key : string
 {
     First = "qwerty",
     Last = "zaqy"
 }
 
 void main()
 {
     enum data = [Key.First, Key.Last];
     mixin DeclFlag!(data);
 
     static foreach(value; data)
     {
         writeln(mixin("has" ~ value));
     }
 }
The output is:
 true
 true
But in template mixin DeclFlag all variables are inited with "false" value! Also with AST switch I get code where there aren't any lines with text "bool hasqwerty = false;" or "bool haszaqy = false;". What happens?
Apr 01
parent ag0aep6g <anonymous example.com> writes:
On 01.04.19 18:31, Andrey wrote:
 Also with AST switch I get code where there aren't any lines with text 
 "bool hasqwerty = false;" or "bool haszaqy = false;". What happens?
Compiler bug. https://issues.dlang.org/show_bug.cgi?id=19479
Apr 01