Help me investigate a bug to file it.
monarch_dodra
monarchdodra at gmail.com
Mon Jul 8 14:45:48 PDT 2013
On Monday, 8 July 2013 at 18:55:30 UTC, Artur Skawina wrote:
> 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?
Yeah. It's not a runtime test. In this case, I *also* need to
make sure that the slie operation accepts a size_t arg. If I use
size_t.min, it statically evaluates to zero, so the test becomes
sens-less: saying "fun(size_t.min)" works doesn't actually
guarantee you can pass a size_t: it may actually only accepts
ubytes or short indexing.
But I guess that is a detail in the scope of the original problem.
> 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...
But, the "context pointer" *should* be defined as whatever the
owner of the indexing/slicing object is, no? In this case, it's
simply _input. It has nothing to do with the "this" pointer being
available...
If anything, it kind of worries me about *what* the
implementation is doing with the this pointer, but I haven't been
able to "trick" it into calling a wrong function.
> Does declaring the opDollar "function" as `static` fix it?
>
> artur
Yes. It does fix it. I think you put your finger exactly on where
the issue is. I'll report it in the morning. Thank you for
participating :)
More information about the Digitalmars-d-learn
mailing list