More on purity

bearophile bearophileHUGS at lycos.com
Wed Dec 21 13:04:24 PST 2011


Timon Gehr:

> This particular case should work, because there is no possibility 
> parameters and return value alias.

The good thing is that this case can be fully determined at compile-time. The bad thing is that increases the complexity of D purity for the programmer that has to use it.


> Have you already filed an enhancement 
> request about this?

I have not filed a diagnostic enhancement regarding the last part of my post, but I have filed an enhancement on the main problem. Sometimes design decisions need to be discussed here and not in Bugzilla.


 However, as soon as it looks like this:
> 
> Object[] foo3(const Object[] a) pure {
>      // ...
> }
> 
> Then it cannot compile when passed a mutable or const array anymore, whereas
> 
> Object[] foo3(in Object[] a) pure {
>      // ...
> }
> 
> Should work even then (but preferably after DMD starts to actually 
> enforce 'scope').

Nice.


> Another thing: This should always work:
> // T[] foo2(const T[]){...}; immutable T[] arr1
> immutable T[] r3 = foo2(arr1); // currently error

This is yet another situation, I think.

Bye,
bearophile


More information about the Digitalmars-d mailing list