Uncallable delegates
Walter Bright
newshound2 at digitalmars.com
Fri May 15 02:42:12 UTC 2026
On 5/14/2026 2:55 PM, Timon Gehr wrote:
> ```d
> import std;
>
> @safe:
> class C{ int x=2; }
>
> Tuple!(int*,immutable(int)*) createBadAliasing(){
> static foo()pure{
> auto c = new C;
> auto dg = ()=>&c.x;
> return tuple(dg,c);
> }
> immutable t = foo();
> return tuple(t[0](),&t[1].x);
> }
>
> void main(){
> auto ps = createBadAliasing();
> auto p = ps[0], q = ps[1];
> static assert(is(typeof(p)==int*));
> static assert(is(typeof(q)==immutable(int)*));
> assert(p is q);
> auto x = *q;
> *p = 3;
> assert(x == 2);
> assert(x == *q);
> assert(2 + *q == 5);
> }
> ```
Timon, I appreciate you stepping in to help. Your deductions are always insightful.
But, sadly, I wish for examples that are as small as possible, not ones with
templates, tuples, pure functions, static functions, nested functions, every
module in Phobos, a class C that doesn't appear to serve any purpose, and other
complications. I don't know which of the assertions should hold, and which ones
are salient to your conclusion. I have a very small brain.
Nearly every example of "I am confused by dip1000" is the result of overly
complicated examples. Pare away *everything* that does not contribute to the
problem, and then things come into focus.
For example, the examples I have written in my comments in this thread.
More information about the dip.development
mailing list