[Issue 16058] `immutable delegate()` and `immutable delegate() immutable` are considered equal but treated differently

d-bugmail at puremagic.com d-bugmail at puremagic.com
Tue Apr 13 00:25:17 UTC 2021


timon.gehr at gmx.ch changed:

           What    |Removed                     |Added
                 CC|                            |timon.gehr at gmx.ch

--- Comment #4 from timon.gehr at gmx.ch ---
(In reply to Kenji Hara from comment #3)
> From the type qualifier transitivity, immutable(int* delegate()) should be
> same with immutable(int* delegate() immutable).
> ...

This does not follow from transitivity because the postfix `immutable` also
annotates the implicit context parameter of the function pointer while the
`immutable` qualifier on the delegate a priori does not.

If those two types are conflated this actually leads to type system

auto foo()pure{
    int x;
    return ()pure{ return x++; };

void main(){
    immutable dg=foo(); // can convert to immutable as it's a strongly pure
    import std.stdio;
    writeln(dg()," ",dg()); // 0 1, immutable context is modified


More information about the Digitalmars-d-bugs mailing list