Enhanced UFCS

Quirin Schroll qs.il.paperinik at gmail.com
Mon Jul 21 10:57:44 UTC 2025


On Monday, 26 May 2025 at 14:18:36 UTC, Dennis wrote:
> I've encountered this limitation as well, and like this idea of 
> more uniformity. But as Steven said, care needs to be taken 
> with overloads:
>
> ```D
> // foo.d
> int f(S* x) => 2; // in an imported module
>
> // bar.d
> import foo;
> int f(ref S x) => 1; // in this module
>
> S* ptr;
> void main()
> {
>     writeln(ptr.f); // 1 or 2?
> }
> ```
>
> On Monday, 26 May 2025 at 07:55:20 UTC, xoxo wrote:
>> Here’s a minimal example:
>
> As of 2.111, you can do `ref Vector ptr = v;` instead of using 
> a pointer, so perhaps you can use a different motivating 
> example.

Aren’t `foo.f` and `bar.f` in different overload sets and 
therefore:
- Without the proposed change, `bar.f` is called since `foo.f` 
isn’t callable using a pointer.
- With the proposed change, `foo.f` and `bar.f` are both viable 
in distinct overload sets, therefore it’s an ambiguity error.

The proposal is a breaking change for this reason.


More information about the dip.ideas mailing list