Help me investigate a bug to file it.
Artur Skawina
art.08.09 at gmail.com
Mon Jul 8 11:55:14 PDT 2013
On 07/08/13 19:54, monarch_dodra wrote:
> 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!
> }
> 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:
Did you really mean size_t.*max* above?
Anyway, when '$' is rewritten as 'opDollar' and that is defined
as a non-static method, it would be surprising if calling the
method did work w/o any context pointer...
> //----
> 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;
> //----
Does declaring the opDollar "function" as `static` fix it?
artur
More information about the Digitalmars-d-learn
mailing list