[Issue 18523] New: In the language spec, clarify member function vs UFCS lookup semantics

d-bugmail at puremagic.com d-bugmail at puremagic.com
Mon Feb 26 04:38:09 UTC 2018


https://issues.dlang.org/show_bug.cgi?id=18523

          Issue ID: 18523
           Summary: In the language spec, clarify member function vs UFCS
                    lookup semantics
           Product: D
           Version: D2
          Hardware: x86
                OS: Windows
            Status: NEW
          Severity: enhancement
          Priority: P1
         Component: dlang.org
          Assignee: nobody at puremagic.com
          Reporter: johnnymarler at gmail.com

I was unable to find in the spec what the rule is on function lookup in the
case where you have both a member function and a UFCS function with the same
name, but the arguments in the call match the UFCS function but not the member
function, i.e.

struct Foo
{
    void bar(int x) { }
}
void bar(ref Foo foo, string x) { }


void main()
{
    Foo foo;
    foo.bar("hello");
}


Compiling this results in:

Error: function Foo.bar (int x) is not callable using argument types (string)


It appears that a member function matching will always have priority over a
UFCS function even if the arguments don't match the member function.  This
should be clarified in the spec.

--


More information about the Digitalmars-d-bugs mailing list