Implicit conversion of struct with methods to immutable in pure function fails

Timoses timosesu at gmail.com
Thu Jul 19 08:43:48 UTC 2018


On Thursday, 19 July 2018 at 06:35:36 UTC, Simen Kjærås wrote:
> On Wednesday, 18 July 2018 at 11:28:54 UTC, Timoses wrote:
>> But why is a context pointer a problem? Is it problematic 
>> because the context pointer to the main scope can not 
>> guarantee `immutable`? E.g. if I happened to use data from 
>> main in a function of the immutable struct then... well then 
>> what?
>> The struct would still be immutable, but what would prevent a 
>> function from using non-immutable data?
>
> It's a known bug: https://issues.dlang.org/show_bug.cgi?id=18563
> In the associated discussion 
> (https://forum.dlang.org/thread/p7lp2b$1jod$1@digitalmars.com), 
> Steven Schveighoffer points out that an immutable struct may be 
> passed to other threads, which would give one thread access to 
> another thread's stack. This could be a good enough reason to 
> prevent this kind of conversion, but a better error message 
> would still make sense.
>
> --
>   Simen

Thanks so much for the pointer, Simen. Interesting discussion.


More information about the Digitalmars-d-learn mailing list