April 05, 2014 templates, enums, CT reflection: compiler bug or not? | ||||
---|---|---|---|---|
| ||||
i stumbled upon something strange while wondering around meta/codegen-lands. it took me almost a week to reduce it to the following test case. i have no clue what is going on, whether i have entered bug territory or just encountered my own limitations.... mind you, i have 2 issues with the code: (1) that my template, which uses __traits(compiles, ...), under certain circumstances (aka 'if things are getting complicated') fails to see symbols that one could argue are valid in this scope. (annoying maybe, but not my main problem) (2) the strange compiler error i get when using the template on itself, but only if it is not the first time that the instantiation is used. this is my real issue cause i don't know how to work around this. during my attempts to reduce this, starting from much more complicated code, i encountered all sorts of errors, including ICE and __error stuff. so am i being stupid or is it a compiler bug? cheers, det ===CODE=== module demo; template valid(string mem){ pragma(msg, "instantiation of valid with: "~mem); static if( !__traits( compiles, mixin(mem) ) ){ enum valid = false; }else{ enum valid = true; } } enum ok = valid!"foo"; pragma(msg, ok ); // -> true // fine, recognizes 'foo' in module scope enum works = valid!"fails"; pragma(msg, works ); // -> false // problematic, fails to see 'fails' in module scope enum dummy = valid!"fails"; pragma(msg, dummy ); // -> false // same behavior, as long as you are not testing yourself enum fails = valid!"fails"; // Error: variable demo.fails had semantic errors when compiling // NOTE: if you comment out the first two usages of valid!"fails", it will work here, // although it will result in "false" // pragma(msg, fails ); enum foo = 42; void main(){} |
April 06, 2014 Re: templates, enums, CT reflection: compiler bug or not? | ||||
---|---|---|---|---|
| ||||
Posted in reply to captaindet | no one any ideas? well, i filed two bug reports for now: https://d.puremagic.com/issues/show_bug.cgi?id=12532 https://d.puremagic.com/issues/show_bug.cgi?id=12533 |
Copyright © 1999-2021 by the D Language Foundation