Bug 24005 – UFCS: The non-member function call can be uniform/universal, too

Status
NEW
Severity
enhancement
Priority
P1
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2023-06-21T09:12:25Z
Last change time
2024-12-13T19:29:49Z
Assigned to
No Owner
Creator
Bolpat
Moved to GitHub: dmd#20303 →

Comments

Comment #0 by qs.il.paperinik — 2023-06-21T09:12:25Z
UFCS makes it possible to call a non-member function as if it were a member function of the first parameter’s type. The reverse is not true, however. A member function cannot be called as if it were a non-member function that takes the aggregate type that contains it as the first parameter explicitly: ```d struct S { void mem() {} } void nonmem(S) {} void main() { S s; s.mem(); // ok mem(s); // fails s.nonmem(); // ok (UFCS) nonmem(s); // ok } ``` I suggest to make the non-member call syntax universal as well. The same as preferring the member function in member function syntax over an eponymous non-member function in scope, we prefer the non-member function in the non-member function call syntax over an eponymous member function of the type of the first argument. This, plus https://issues.dlang.org/show_bug.cgi?id=24004, would make it unnecessary to remember if a functionality is provided via a non-member or member function in quite a lot of cases. A bit of nomenclature: UNFCS: Universal non-member function call syntax. The (new) mechanic that `mem(obj)` works because `obj` has a member `mem`. UMFCS: Universal member function call syntax: The (already present) mechanic that `obj.nonmem` works because a non-member function takes `typeof(obj)` as its first parameter. UFCS: Umbrella term for both UNFCS and UMFCS.
Comment #1 by robert.schadek — 2024-12-13T19:29:49Z
THIS ISSUE HAS BEEN MOVED TO GITHUB https://github.com/dlang/dmd/issues/20303 DO NOT COMMENT HERE ANYMORE, NOBODY WILL SEE IT, THIS ISSUE HAS BEEN MOVED TO GITHUB