On Thursday, 25 June 2015 at 03:12:47 UTC, Steven Schveighoffer wrote:
A curious thing though. All the tests for things like:

assert(setExtension("file", "ext") == "file.ext");

do not trigger a call to eager.

But it passes? That's bizarre. (My dmd is apparently too old to compile this, it segfaults when I try!)

assert(setExtension("file", "ext").array == "file.ext");

I did experience this in my proof-of-concept because I didn't implement .length. So when array checked hasLength, it found it through the alias this, which called eager. (That's also why I did a foreach loop instead of just returning array(this). Well, that and the auto-decode nonsense, but array would be a recursive call and stack overflow anyway).

But since you did implement a length function, that shouldn't be happening. Maybe it passes the check in StringTypeOf though: is(T : const char[]) might pass due to the alias this too. Not sure.

(An interesting point here though is since alias this DOES return a string, any duck-type checks or implicit conversion checks will also pass what it passes... and work, it'll just silently allocate the string. Which is no regression! The status quo is it allocates that string EVERY time anyway. But it also isn't ideal. Someone earlier said we can probably apply @nogc to everything but the eager method. I think that'd work, and then at least the allocations wouldn't be silent anymore - the @nogc attribute at the call site can catch them.)



These two things are weird, but I'm sure they're just bugs that we can handle. In the morning, I'll try a git dmd and see if I can play with it a little, right now I'm just guessing since it won't build on my current setup.

Reply via email to