On Sunday, 28 June 2015 at 00:25:47 UTC, Jonathan M Davis wrote:
[snip]
it's an open question as to whether any kind of property enforcement will ever be in

I should probably note that a long term consequence of not having full property enforcement is that whether parens are used or not in generic code is going to be a problem. For, instance,

    template isInputRange(R)
    {
        enum bool isInputRange = is(typeof(
        (inout int = 0)
        {
            R r = R.init;     // can define a range object
            if (r.empty) {}   // can test for empty
            r.popFront();     // can invoke popFront()
            auto h = r.front; // can get the front of the range
        }));
    }

requires that empty and front be called without parens, which means that front and empty can be enums or variables or anything else which is going to fit the syntax in the code above and not just functions. So, you can't _ever_ be calling front or empty with parens in generic code if you want your code to work with ranges in general rather than the small set of ranges that you might be using at the moment. But the compiler doesn't enforce that right now at all. It just enforces that the ranges themselves be such that front and empty be usable without parens.

In addition, it requires that popFront be used _with_ parens, but the only case where it would break code if you didn't would be if someone had declared popFront as callable rather than a function, since using it without parens as a function would work - but not as callable. Now, realistically, pretty much no one is going to do that, but technically, according to the API requirements, it's perfectly legitimate to do so, and the compiler doesn't protect against anyone from writing code which calls popFront without parens.

Full property enforcement would fix these issues, but we're never going to get it. So, we will always have to worry about generic code which uses parens where it shouldn't or doesn't use them where it should. How big an issue this will be is an open question, but being lax with syntax (like we are with parens on functions) doesn't jive well with generic code, so it's something that we're going to have to watch out for.

- Jonathan M Davis

Reply via email to