Uncallable delegates

Timon Gehr timon.gehr at gmx.ch
Sat May 16 06:34:53 UTC 2026


On 5/16/26 04:05, Walter Bright wrote:
> On 5/14/2026 7:36 PM, Timon Gehr wrote:
>> Specifically which proposed behavior are you not able to explain in 
>> terms of classes?
> 
> The overriding of class functions must behave the same as implicit 
> conversions on delegates.

This is not correct. You can make it work that way and it would at least 
be sound, but it is also really weird.

Consider:

```d
void main(){
     immutable x = new int(2);
     auto foo()immutable => x;
     auto bar() => x;

     auto dg1 = &foo;
     auto dg2 = &bar;
     //dg2 = dg1; // error

     auto baz() => dg1(); // ok
     dg2 = &baz; // ok
}
```

There is no reason at all to disallow the first assignment.

Delegates are not the same as class methods. The reason is that class 
methods accept an external `this` pointer and delegates have an internal 
`this` pointer. This also affects conversions.


More information about the dip.development mailing list