Uncallable delegates

Timon Gehr timon.gehr at gmx.ch
Sat May 16 07:31:06 UTC 2026


On 5/16/26 08:15, Timon Gehr wrote:
> On 5/16/26 06:35, Walter Bright wrote:
>> On 5/15/2026 7:45 PM, Richard (Rikki) Andrew Cattermole wrote:
>>> To agree with Walter here, if there are problems with pure please 
>>> split them off into their own ticket.
>>
>> Already done: https://github.com/dlang/dmd/issues/23125
>> ...
> 
> I approve, but it's indeed an unrelated problem.

I take that back, it's not even a problem. This bug report was correctly 
closed as invalid 14 hours ago.

Implicit conversions of a delegate to `pure` is correctly disallowed:

```d
class C{
     void notPure(){ }
}

void main(){
     void delegate()pure dg = &new C().notPure; // error
}
```

```
Error: cannot implicitly convert expression `&(new C).notPure` of type 
`void delegate()` to `void delegate() pure`
```

I.e., delegates don't even implicitly convert to `pure`.


There is also not even a problem with inheritance:

```d
class C{
     void yesPure()pure{ }
}

class D:C{
     override void yesPure(){ }
}

static assert(is(typeof(&new D().yesPure) == void delegate()pure));
```

I.e., you made this bug up, it is not real. `D.yesPure` is `pure` 
because it inherits it when overriding the parent method.




More information about the dip.development mailing list