When I tried to use UFCS to call a nested function, I was surprised that it didn't work. Then I looked up the document, and found out this is actually by design. However, I found the reason listed in the document very unconvincing.

I will copy the example here:

int front(int[] arr) { return arr[0]; }

void main()
{
    int[] a = [1,2,3];
    auto x = a.front();   // call .front by UFCS

    auto front = x;       // front is now a variable
    auto y = a.front();   // Error, front is not a function
}

class C
{
    int[] arr;
    int front()
    {
        return arr.front(); // Error, C.front is not callable
                            // using argument types (int[])
    }
}

Looks like all of these examples can be resolved by just letting the compiler keep trying the next symbol after the first one failed, just like doing an overload resolution. So what's the problem with doing that?

Also can't the compiler simply lower a.name to name(a) if 'name' is not found in 'a', then compile that?

Reply via email to