More on purity
bearophile
bearophileHUGS at lycos.com
Wed Dec 21 11:53:51 PST 2011
This was discussed a little in D.learn. Is code like this going to compile in some future DMD versions, like DMD 2.058? I hit situations like this often in my code:
int[] foo1(immutable int[] a) pure {
return new int[a.length];
}
int[] foo2(in int[] a) pure {
return new int[a.length];
}
void main() {
immutable int[] arr1 = [1, 2, 3];
immutable int[] r1 = foo1(arr1); // OK
const int[] arr2 = [1, 2, 3];
immutable int[] r2 = foo2(arr2); // error
}
Currently it gives:
Error: cannot implicitly convert expression (foo2(arr2)) of type int[] to immutable(int[])
If code like that can't be accepted in future D/DMD versions, then I think DMD should give an error message that explains why the r2 implicitly conversion is not acceptable (while the implicitly conversion to r1 is acceptable).
Bye,
bearophile
More information about the Digitalmars-d
mailing list