Thread overview
[Issue 16058] `immutable delegate()` and `immutable delegate() immutable` are considered equal but treated differently
May 24, 2016
Eyal Lotem
May 24, 2016
Sobirari Muhomori
May 24, 2016
ag0aep6g@gmail.com
Jun 02, 2016
Kenji Hara
Jan 13, 2021
Bolpat
Apr 13, 2021
timon.gehr@gmx.ch
Dec 17, 2022
Iain Buclaw
May 24, 2016
https://issues.dlang.org/show_bug.cgi?id=16058

Eyal Lotem <eyal.lotem@gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |eyal.lotem@gmail.com

--- Comment #1 from Eyal Lotem <eyal.lotem@gmail.com> ---
I think it makes sense for the types not to be considered equal. (Head-mutable ptrs to immutable data exist, so why should delegates be inconsistent?)

--
May 24, 2016
https://issues.dlang.org/show_bug.cgi?id=16058

Sobirari Muhomori <dfj1esp02@sneakemail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           See Also|                            |https://issues.dlang.org/sh
                   |                            |ow_bug.cgi?id=1983

--
May 24, 2016
https://issues.dlang.org/show_bug.cgi?id=16058

--- Comment #2 from ag0aep6g@gmail.com ---
(In reply to Eyal Lotem from comment #1)
> I think it makes sense for the types not to be considered equal. (Head-mutable ptrs to immutable data exist, so why should delegates be inconsistent?)

A head mutable delegate would be `void delegate() immutable`, no? That is considered different from the two types this is about.

--
June 02, 2016
https://issues.dlang.org/show_bug.cgi?id=16058

--- Comment #3 from Kenji Hara <k.hara.pg@gmail.com> ---
>From the type qualifier transitivity, immutable(int* delegate()) should be same
with immutable(int* delegate() immutable).

The root problem is in dmd implementation, TypeNext.makeXXX functions. Fixing those implementation bugs is not difficult.

--
January 13, 2021
https://issues.dlang.org/show_bug.cgi?id=16058

Bolpat <qs.il.paperinik@gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |qs.il.paperinik@gmail.com

--
April 13, 2021
https://issues.dlang.org/show_bug.cgi?id=16058

timon.gehr@gmx.ch changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |timon.gehr@gmx.ch

--- Comment #4 from timon.gehr@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 unsoundness:

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

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

--
December 17, 2022
https://issues.dlang.org/show_bug.cgi?id=16058

Iain Buclaw <ibuclaw@gdcproject.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Priority|P1                          |P3

--