Uncallable delegates
Dukc
ajieskola at gmail.com
Wed May 13 20:30:43 UTC 2026
On Wednesday, 13 May 2026 at 20:06:29 UTC, Walter Bright wrote:
> 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.
Yes, this is what causes the error - and rightly so!
> 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.
Exactly. I think we're now talking about the same thing.
>
> > 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.
Yes it is.
Returning to the DIP, the issue with the present rules are that
calling a `const` delegate (or equally `immutable`, `shared` or
`inout` delegate) without the `const` for the context parameter
is allowed. It shouldn't be, just like the equivalent function
pointer rewrite we just discussed isn't. My DIP is proposing
disallowing it, along with changes to the qualifier casting rules
of delegates.
> 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.
This is orthogonal to this discussion. It might help, but you can
specify parameters for the context parameter even with the
present language and we both understand the existing syntax.
More information about the dip.development
mailing list