Uncallable delegates
Walter Bright
newshound2 at digitalmars.com
Wed May 13 20:06:29 UTC 2026
On 5/13/2026 12:32 AM, Dukc wrote:
> We can conclude that calling `const(void delegate(int))` is fundamentally
> unsound. It can't be made to work without type system breaking casts.
"Unsound" means it leads to corruption of the type system, such as being able to
modify an immutable value. Unsound would mean something like 2+2=5.
If I understand what you're saying, the issue here is applying the `const` type
specifier not being applied to the argument to the delegate's `context` pointer.
Consider:
```
int abc(int*);
auto fp = const(&abc);
```
This means we cannot rebind fp to another function.
It does not mean fp's function parameter is now `const int*`.
In other words, transitivity does not apply to the parameter list.
> Note that this does not apply to const(void delegate(int) const).
That's exactly as intended. The second const applies to the hidden context
parameter.
There has been endless confusion in D about attributes being attached to the
implicit `this` pointer. A great deal of the dissatisfaction about dip1000 is
attributable to this. I've been considering a proposal to enable being able to
explicitly list the hidden parameter in the argument list, as it then makes it
straightforward to attach attributes to it.
More information about the dip.development
mailing list