Help me investigate a bug to file it.

monarch_dodra monarchdodra at gmail.com
Mon Jul 8 10:54:21 PDT 2013


Yeah, not very exiting, but I just spent an hour tracking down 
the fix, but now I'd like to track down *what* was making it 
break (my fix was "luck"). This should help Kenji (or others) 
have an easier time fixing it :)

Also, I'm only repro'ing this on linux...

I think there are two things involved here. The first, is 
accessing members of a struct for a static if, in a global scope:

//----
import std.stdio;
import std.range;

struct S(R)
{
     R _input;
     void foo()
     {
         static assert(is(typeof(_input[size_t.max .. 
size_t.max]))); //ok
         static assert(is(typeof(_input[size_t.max .. $]))); //ok
     }
     static assert(is(typeof(_input[size_t.max .. size_t.max]))); 
//ok
     static assert(is(typeof(_input[size_t.max .. $]))); //NOPE!
}

void main()
{
     auto k = iota(0, 1).cycle();
     S!(typeof(k)) s;
}
//----

As you can see, the static if behaves differently in a function, 
or in the raw body of the struct. Is this normal? Anybody know 
what is going on exactly? I'm trying to get more context here...

-----------------------------------------------

Second, one of the things I found strange was that only *1* of 
the two assertions failed. basically, _input[0 .. 1] is fair 
game, yet, _input[0 .. $] is not? What gives? I put my nose in 
cycles's opDollar. It is written like this:

//----
         private static struct DollarToken {}
         DollarToken opDollar()
         {
             return DollarToken.init;
         }
//----
Nothing special about it. Just a function that returns an object. 
Declaring it const/nothrow/@safe *and* pure does not fix the 
problem...

*HOWEVER* declaring it as a manifest constant *does* fix the 
issue:
//----
         private static struct DollarToken {}
         enum opDollar = DollarToken.init;
//----

------------------------------------------------

I think I've run into "global static ifs using members" issues 
before, but just figured I wasn't allowed to use them. 
Apparently, to issue is more subtle than this. I have *no* idea 
how to file this, I have no idea what the rules are. Any insight?


More information about the Digitalmars-d-learn mailing list