Help me investigate a bug to file it.
Artur Skawina
art.08.09 at gmail.com
Mon Jul 8 15:43:09 PDT 2013
On 07/08/13 23:45, monarch_dodra wrote:
> 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.
Didn't think of that; these implicit narrowing conversion can be, umm,
surprising. But as long as the right overload gets picked, I guess
they're safe. Thanks for the explanation.
>> 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.
It's just like
struct S {
auto opDollar() { return 42; }
enum a = opDollar();
}
This can't work - there is no S object to call the method with.
enum a = S.init.opDollar();
would work, just as making the method static.
>> Does declaring the opDollar "function" as `static` fix it?
>
> 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 :)
Thank you for still trying to improve the std lib.
I gave up on using it, other than for toy examples, long time ago.
Hopefully it will be usable at some point.
artur
More information about the Digitalmars-d-learn
mailing list