www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 16058] New: `immutable delegate()` and `immutable delegate()

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

          Issue ID: 16058
           Summary: `immutable delegate()` and `immutable delegate()
                    immutable` are considered equal but treated
                    differently
           Product: D
           Version: D2
          Hardware: All
                OS: All
            Status: NEW
          Keywords: accepts-invalid
          Severity: normal
          Priority: P1
         Component: dmd
          Assignee: nobody puremagic.com
          Reporter: ag0aep6g gmail.com

Spin-off from issue 16056.

dmd considers the two types to be equal:

----
alias A = immutable int* delegate();
alias B = immutable int* delegate() immutable;
static assert(is(A == B)); /* passes */
----

That's ok. But it treats them differently.

This is accepted with `-version=V1`, but it's rejected with `-version=V2`:

----
version (V1) alias T = immutable void delegate();
version (V2) alias T = immutable void delegate() immutable;

void main()
{
    int x = 1;
    T dg = { ++x; };
}
----

Both V1 and V2 should be rejected.

Furthermore, when you use both types, the first one determines how the second
is treated.

This is accepted:

----
void main()
{
    int x = 1;
    immutable void delegate() dg1 = { ++x; };
    immutable void delegate() immutable dg2 = { ++x; };
}
----

Swap the two delegates lines and both are rejected. Again, both variants should
be rejected.

All this applies to const as well, of course.

--
May 22 2016