[Issue 8408] Purity calculation should be improved

d-bugmail at puremagic.com d-bugmail at puremagic.com
Thu Dec 6 19:33:54 PST 2012


http://d.puremagic.com/issues/show_bug.cgi?id=8408



--- Comment #8 from Kenji Hara <k.hara.pg at gmail.com> 2012-12-06 19:33:50 PST ---
(In reply to comment #6)
> Is it correct that x1 refused and x2 accepted?
> 
> 
> char[] foo1(int[] arr) pure {
>     return new char[10];
> }
> immutable(char)[] foo2(int[] arr) pure {
>     return new char[10];
> }
> void main(string[] args) {
>     immutable x1 = foo1([1, 2]); // Error: cannot implicitly convert
>     immutable x2 = foo2([1, 2]); // OK
> }

I'm not sure that this should be allowed.
foo1 can rewrite the elements referred from arr, then it is deduced to weak
purity. In current principle, the returned value from weak purity function
cannot be converted to immutable implicitly (it is only allowed for strong
purity function).

If you change the signature of foo1 to:

  char[] foo1(const int[] arr) pure;

Then foo1 will be deduced to strong purity, and implicit conversion to
immutable for initializing x1 will be succeeded.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------


More information about the Digitalmars-d-bugs mailing list