Bug 23779 – UFCS using pointer should be allowed and should automatically take a reference on values

Status
RESOLVED
Resolution
INVALID
Severity
enhancement
Priority
P1
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2023-03-14T14:52:21Z
Last change time
2023-03-14T17:24:02Z
Assigned to
No Owner
Creator
ryuukk_

Comments

Comment #0 by ryuukk.dev — 2023-03-14T14:52:21Z
This code: ``` struct Data { int value; } void something(Data* data) { data.value++; } void main() { Data d; Data* ptr = &d; ptr.something(); // works (&d).something(); // works, but the syntax looks bad d.something(); // doesn't work, compiler should do what i do above and allow it } ``` It is similar to the request here: https://issues.dlang.org/show_bug.cgi?id=8597 But it's the opposite, if the function is declared by accepting a pointer, then this example should be allowed
Comment #1 by razvan.nitu1305 — 2023-03-14T16:46:40Z
The UFCS implementation is already very complex, why would we add another special case? This needs to be a accompanied by strong rationale to have any chances of being accepted. If we were to implement anything, I would rather go the other way around and implement automatic dereferencing with UFCS not automatic address taking. However, I would argue that we should not complicate UFCS any further.
Comment #2 by b2.temp — 2023-03-14T17:24:02Z
what is requested here is an implict conversion from a `D` to a `D*` based on lvaluness. It is not very well described, and maybe a second attempt would be better, so close as "invalid" for the moment.