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.
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).