[Issue 6741] implicit casting of pure-function delegate result to immutable breaks immutability.

2022-12-17 Thread d-bugmail--- via Digitalmars-d-bugs
https://issues.dlang.org/show_bug.cgi?id=6741

Iain Buclaw  changed:

   What|Removed |Added

   Priority|P2  |P4

--


[Issue 6741] implicit casting of pure-function delegate result to immutable breaks immutability.

2014-03-20 Thread d-bugmail
https://d.puremagic.com/issues/show_bug.cgi?id=6741



--- Comment #2 from Steven Schveighoffer schvei...@yahoo.com 2014-03-20 
12:57:35 PDT ---
It's a bug because when the object is cast implicitly to immutable, it does not
affect the context pointer. In essence, the delegate captures the instance when
it was mutable.

Normally, implicitly casting a pure return to immutable is OK because immutable
is transitive. Since a strong pure function cannot have side effects, the
return must be the only reference to it. However, if it contains a reference to
itself via a delegate, that reference does NOT get cast to immutable.

Why do you think the given code is correct behavior? I should never be able to
do this without casts:

immutable a = ...
assert(a.n == 3);
...
assert(a.n == 4);

BTW, I do not say that a class with delegate members should not be allowed to
be immutable, I'm saying that it should not *implicitly* cast to immutable. In
other words, the code would be allowed if you did:

auto tmp = cast(immutable(A))createAnA(3);

In this case, you are telling the compiler I know what I'm doing.

-- 
Configure issuemail: https://d.puremagic.com/issues/userprefs.cgi?tab=email
--- You are receiving this mail because: ---


[Issue 6741] implicit casting of pure-function delegate result to immutable breaks immutability.

2014-03-19 Thread d-bugmail
https://d.puremagic.com/issues/show_bug.cgi?id=6741


Infiltrator lt.infiltra...@gmail.com changed:

   What|Removed |Added

 CC||lt.infiltra...@gmail.com


--- Comment #1 from Infiltrator lt.infiltra...@gmail.com 2014-03-19 21:20:35 
PDT ---
Why is this a bug?  With the delegate, it is the pointer itself which becomes
immutable, not the pointed-to function.  This appears to be correct behaviour. 
Furthermore, disallowing any delegate-containing object to be immutable seems
unnecessarily strict for no (?) benefit.

-- 
Configure issuemail: https://d.puremagic.com/issues/userprefs.cgi?tab=email
--- You are receiving this mail because: ---