www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - for fun, if questionable - a heisenbug

reply captaindet <2krnk gmx.net> writes:
reported as part of issue 12541
https://d.puremagic.com/issues/show_bug.cgi?id=12541

=== CODE ===

module heisenbug;

//  pragma(msg, __traits(compiles, test) );
// comment in the pragma and 'enum buggy' below will compile fine

enum buggy = valid!(test);
// Error: variable heisenbug.buggy had semantic errors when compiling
pragma(msg, "buggy = "~buggy.stringof);

enum test = 13;

template valid(alias sym){
     enum valid = __traits(compiles, sym);
} // no difference if this template is declared first

void main(){}
Apr 08 2014
parent reply Matej Nanut <matejnanut gmail.com> writes:
On 8 April 2014 22:11, captaindet <2krnk gmx.net> wrote:
 [...]
I noticed it works if you move the enum declaration above the instantiation of template valid.
Apr 08 2014
parent captaindet <2krnk gmx.net> writes:
On 2014-04-08 15:37, Matej Nanut wrote:
 On 8 April 2014 22:11, captaindet<2krnk gmx.net>  wrote:
 [...]
I noticed it works if you move the enum declaration above the instantiation of template valid.
yes, it requires certain conditions to (dis)appear. those i could figure out are in the bug report ( https://d.puremagic.com/issues/show_bug.cgi?id=12541 ). also, of course, if the _traits method is not templated, it always compiles fine. unfortunately, if you want to apply meta stuff on arbitrary/other ppls code, you don't have the luxury of moving declarations around.
Apr 08 2014