immutable bug?

Timon Gehr timon.gehr at gmx.ch
Sat Jan 11 13:16:55 PST 2014


On 01/11/2014 08:16 PM, Maxim Fomin wrote:
> On Saturday, 11 January 2014 at 18:52:39 UTC, Adam D. Ruppe wrote:
>> On Saturday, 11 January 2014 at 18:48:15 UTC, Maxim Fomin wrote:
>>> It is legal exactly because function is marked as pure. Result of
>>> pure function is implicitly convertible to immutable.
>>
>> It shouldn't be here though... the reason it is implicitly convertable
>> is that pure means the result is unique. But, with the hidden this
>> pointer having a reference to the data as well, it obviously is not
>> unique. I think the compiler should catch this; i'd call it a bug.
>
> Creating undefined behavior is not a sufficient reason to be a bug.
> ...

Add a @safe annotation and it is.

> Changelog mentions example with pure struct constructors which provide
> value implicitly castable to immutable. So, strictly speaking current
> behavior is conforming to spec.
>
> You can still argue that the example does not address the issue with
> 'this' parameter, so code should be rejected (which should happen from
> safity aspect). I think this case was not considered when 'unique
> expression' was introduced, so it is yet another hole in type system (to
> be more precise, bug is in spec-language, not compiler).

It is an implementation bug. Implicit conversion to immutable is only 
supposed to work for strongly pure functions.


More information about the Digitalmars-d mailing list