Uncallable delegates

Dukc ajieskola at gmail.com
Wed May 13 08:06:01 UTC 2026


On Wednesday, 13 May 2026 at 02:31:43 UTC, FeepingCreature wrote:
> On Wednesday, 13 May 2026 at 02:19:04 UTC, FeepingCreature 
> wrote:
>
> Addendum: I mean, you can get into hot water much more easily:
>
> ```
> @safe:
>
> class C {
>   int x;
>   void foo() const { meep(); }
> }
>
> C c;
> void meep() { c.x ++; }
>
> void main() {
>   auto c = new C;
>   .c = c;
>   c.foo; // c.x mutates as an effect of a const call!
> }
> ```
>
> As far as I can tell this is totally unstoppable as global 
> functions don't have const anyways. We'd need to consider the 
> global scope as an implicit parameter so that it could be 
> covered by constness even with global functions.

Like Walter said, this is by design. `const` only says you can't 
mutate through it, not that you can't mutate it at all - 
`immutable` is for the latter meaning. So I guess you should add 
`pure` to both `foo` and `del` in the example, or alternatively 
use `immutable` in place of `const`, which would give the 
guarantee of no mutation from outside perspective. The issue 
still persists even if you do this, though.


More information about the dip.development mailing list