Discussion Thread: DIP 1041--Attributes for Higher-Order Functions--Community Review Round 1

ag0aep6g anonymous at example.com
Mon Apr 12 23:36:34 UTC 2021


On Monday, 12 April 2021 at 21:59:50 UTC, Q. Schroll wrote:
> On Monday, 12 April 2021 at 17:21:47 UTC, Timon Gehr wrote:
[...]
>> Your reinterpretation of what delegate qualifiers mean would 
>> need a DIP in its own right and it would hopefully be rejected.
>
> I'm not sure it's a *re-*interpretation. As factually the 
> compiler defines the language at places, you're probably right 
> about the DIP part.

I don't think you can cite DMD on the matter. It contradicts 
itself when it comes to qualified delegates.

You could point at the following code as evidence that DMD allows 
a const delegate with a mutable context:

```d
struct S
{
     int field;
     void method() { field = 42; }
}
void main()
{
     S s;
     const void delegate() d = &s.method;
     d();
}
```

But add one line, and DMD will say the opposite:

```d
alias NotEvenUsed = const void delegate() const; /* the only 
change; rest of the code is identical */
struct S
{
     int field;
     void method() { field = 42; }
}
void main()
{
     S s;
     const void delegate() d = &s.method; /* this is now an error 
*/
     d();
}
```

https://issues.dlang.org/show_bug.cgi?id=16058

This is a case where we can't just say "let's write down in the 
spec what DMD is doing already", because what DMD is doing makes 
no sense.


More information about the Digitalmars-d mailing list